Re: Array question

From: Date: Sun, 26 Sep 2010 14:18:09 +0000
Subject: Re: Array question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-308318@lists.php.net to get a copy of this message
At 3:31 PM -0500 9/25/10, MikeB wrote:
-snip- My question, in the loop, why does tha author use: $results[] = mysql_fetch_array($result); instead of (as I would expect): $results[$j] = mysql_fetch_array($result);? What PHP magic is at work here?
Mike: That's just a shorthand way to populate an array in PHP. One of the reasons for this feature is that somewhere in your code you may not know what the next index should be. So, if you use -- $results[] = $next_item; -- then the $next_item will be "automagically" added to the next available index in the array. So you may be right in calling it "PHP magic" because I have not seen this in other languages. Understand? Cheers, tedd -- ------- http://sperling.com/

« previous php.general (#308318) next »