You are here: Re: Any difference between these two? « PHP Programming Language « IT news, forums, messages
Re: Any difference between these two?

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация