Page 1 of 1

PHP array

Posted: Wed Jun 22, 2011 12:59 am
by anp24
Hello,
Can I initialize the array in PHP as shown below.

$myarray=array();

this is because I don't know the exact values at the time of initialization, the values will be filled from the database in the while loop.

Thanks
Regards

Re: PHP array

Posted: Wed Jun 22, 2011 1:21 am
by twinedev
Yes

Re: PHP array

Posted: Wed Jun 22, 2011 9:52 pm
by xtiano77
Yes, you can initialise an array like that:

$a = array( );

Afterwards you can add values by using the following code:

$a[ ] = value;

Or if you are using a "for" loop, you can do it like so:

$a[$i] or $a[++$i]

Hope this helps.


P.S. Checkout this link, it may help with some more functions: http://www.w3schools.com/php/php_ref_array.asp