Reply to Re: multidimensional array declaration in php

Your name:

Reply:


Posted by Markus Ernst on 07/17/06 12:45

ybakos schrieb:
>>
>>i hope to use something like:
>>
>>a[$i][0];
>>
>>a[$i][1];
>>
>>a[$i][2];

[...]

> for (...) {
> $newArray = array(1,2,3)
> $myarray[] = $newArray;
> }

As Arrays are passed by value and not by reference, you can define the
new array outside the for loop.

$myArray = array();
$newArray = array(0, 0, 0);
for ($i=0; $i<10000; $i++) {
$myArray[] = $newArray;
}

or

$myArray = array();
for ($i=0; $i<10000; $i++) {
$myArray[] = array(0, 0, 0);
}

I don't know which is faster.
Anyway this does not explain the undefined offset notice, and it does
not really answer why one should do this at all :-)

--
Markus

[Back to original 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

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