PHP array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anp24
Forum Newbie
Posts: 13
Joined: Wed Jul 11, 2007 6:34 am

PHP array

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: PHP array

Post by twinedev »

Yes
xtiano77
Forum Commoner
Posts: 72
Joined: Tue Sep 22, 2009 10:53 am
Location: Texas

Re: PHP array

Post 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
Post Reply