"R" <ruthless@poczta.onet.plwrote in message
news:1153995282.205183.296370@75g2000cwc.googlegro ups.com...
Quote:
Hi All,
>
I'm using eval and arrays in foreach and have trouble with adding
elements
to them - I'm talking about the '[]' operator.
>
My code is:
>
// creates arrays with the names of columns in keys array
foreach ($keys as $k) {
eval("\$$k = array();");
}
$$k = array();
works fine, no reason to use eval.
Quote:
// fills dynamically columns' arrays with its values
foreach ($array as $a) {
foreach ($keys as $k) {
// parse error
//eval("\$$k[] = $a[$k];");
Again, just use:
$$k[] = $a[$k];
no eval needed here either.
Quote:
// works fine
eval("array_push(\$$k, $a[$k]);");
And here too:
array_push($$k, $a[$k]);
Quote:
}
}
>
I used array_push and it works fine but...
Your home assignment is to study a wonderful language feature called
"variable variables":
http://php.net/manual/en/language.va...s.variable.php
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)