ScotlandPHP 2019


Please answer this simple SPAM challenge: six plus zero?
(Example: nine)

The Note You're Voting On

gunter dot sammet at gmail dot com
12 years ago
I tried to create an array with n depth using a recursive function passing array references around. So far I haven't had much luck and I couldn't find anything on the web. So I ended up using eval() and it seems to work well:
foreach(array_keys($this->quantity_array) AS $key){
$this->quantity_array[$key] > 0){
$combinations = explode('-', $key);
$eval_string = '$eval_array';
array_keys($combinations) AS $key2){
$option_key_value = explode('_', $combinations[$key2]);
$eval_string .= '['.$option_key_value[0].']['.$option_key_value[1].']';
$eval_string .= ' = '.$this->quantity_array[$key].';';

This produces an n dimensional array that will be available in the $eval_array variable. Hope it helps somebody!

<< Back to user notes page

To Top