php - Creating multidimensional array -


i have array this: $test = array(20, 30, 40);

and want set multi-dimension array using these values: $example[20][30][40] = 'string'

how can this?

note: "20, 30, 40" example, program print integers, , want set multi-dimension array these values , can more 3 values.

you way:

$example[$test[0]][$test[1]][$test[2]] = 'string' 

or if size of array variable need recursive function fill array.

function fill_up($content, $value){     $index = array_shift($content);     if(count($content)){         return array($index => fill_up($content, $value));     } else {         return array($index => $value);     } }  $example = array(20,30,40); $value = 'test'; var_dump(fill_up($example, $value)); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -