I have an array that contains 4 elements (sub-arrays).
$orders = array( array(), array(), array(), array() );
Now, I want to tell each sub-array to append items to itself, so I iterate through them like so:
for($i=0; $i<4 ; $i++ ) {
$orders[$i][] = rand(); // this does not work, unexpected '['
}
What is a better way for accomplishing this?
You had a syntax error:
for($i=0; $i<4 ; $i++ ) {
$orders[$i][] = rand(); // this does not work, unexpected '['
}
But this might be even better:
foreach($orders as $key => $order){
$orders[$key][] = rand();
}