Voting

: seven minus two?
(Example: nine)

The Note You're Voting On

gunter dot sammet at gmail dot com
16 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:
<?php
     
foreach(array_keys($this->quantity_array) AS $key){
        if(
$this->quantity_array[$key] > 0){
         
$combinations = explode('-', $key);
         
$eval_string = '$eval_array';
          foreach(
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].';';
          eval(
$eval_string);
        }
      }
?>

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