In the example are two arrays, but actually may be other number of arrays (i do not know how many arrays i may have).
$some_name = array ( "Volvo_0",220,180, );
$array_name_for_variable[]='some_name';//here i create another array latter to loop through
$another_name = array ( "Volvo_1",221,181, );
$array_name_for_variable[]='another_name';
In the example i just want to print_r the arrays i may have. So i loop through $array_name_for_variable
. Like
foreach( $array_name_for_variable as $i_array_name_for_variable => $val_array_name_for_variable ) {
trying to print particular array (like print_r($some_name)
), using this
echo '<pre>', print_r($['val_array_name_for_variable'], true), '</pre> $val_array_name_for_variable __<br/>';
but see error Parse error: syntax error, unexpected '[', expecting T_VARIABLE or '$'
}
This print_r($['val_array_name_for_variable'])
is wrong. Tried this print_r( $[$val_array_name_for_variable] );
. Also got error.
Any ideas what need to change.
Why all this and what i need...
I have 12 arrays, but i do not know which of 12 would be used in one particular page.
So page loads, some of the 12 arrays are defined (used).
I may write like if array_1 exists, then long html code using variables from the array_1.
Then again if array_2 exists and not empty, then repeat the same html code with variables from array_2.
But instead of copy-paste (repeating) html code i decided to loop through arrays existing in opened page and the long html code write only once.