[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] Array question
From:       tedd <tedd.sperling () gmail ! com>
Date:       2010-09-26 14:18:09
Message-ID: p06240803c8c5043ed1a8 () [192 ! 168 ! 1 ! 104]
[Download RAW message or body]

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/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic