create multidimensional array with n depth

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all:
I've been trying to create a multidimensional array with n depth in php. 
Tried to use a recursive function passing array references by pointers but 
seems like it's not possible or I still don't understand this subject 
enough. Finally managed to get it going using the eval function. The code 
below converts a seperated string into a multi dimensional array with n 
depth:

e.g. $array['1_20-2_16-7_14'] = 12 will become 
$eval_array[1][20][2][16][7][14] = 12

      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);
        }
      }

Using eval() for it seems a bit expensive to me. So I've been wondering if 
there is an easier way?
TIA

Gunter 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux