You are here: using [] inside eval function « PHP Programming Language « IT news, forums, messages
using [] inside eval function

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация