|
Posted by NC on 12/07/05 10:30
Chung Leong wrote:
> Is there anything funcationally difference between the following
> snippets:
>
> // first
> $lines[] = array();
> $line =& $lines[count($lines) - 1];
>
> // second
> $line = array();
> $lines[] =& $line;
Yes. The first example assumes that the array is numeric and there are
no gaps in numbering. If there are gaps, $lines[count($lines) - 1]
will not return the last element in the array. Consider this snippet:
$lines = array('Zero', 'One', 'Two', 'Three', 'Four');
unset($lines[1]);
print_r($lines); /* Outputs:
Array
(
[0] => Zero
[2] => Two
[3] => Three
[4] => Four
) */
echo $lines[count($lines) - 1], "\r\n"; // outputs "Three"...
The second example makes no such assumption and simply adds another
element to $lines...
Cheers,
NC
[Back to original message]
|