Posted by R on 07/27/06 10:14
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();");
}
// fills dynamically columns' arrays with its values
foreach ($array as $a) {
foreach ($keys as $k) {
// parse error
//eval("\$$k[] = $a[$k];");
// works fine
eval("array_push(\$$k, $a[$k]);");
}
}
I used array_push and it works fine but...
'Note: If you use array_push() to add one element to the array it's
better to use $array[] = because in that way there is no overhead of
calling a function.'
It's not a matter of life and death but is there some way to use the []
inside the eval
function?
thanks in advance for Your help
best regards R
Navigation:
[Reply to this message]
|