|
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
Navigation:
[Reply to this message]
|