How to create array items by specify a key that includes hierachy ?
Posted
by Relax
on Stack Overflow
See other posts from Stack Overflow
or by Relax
Published on 2010-04-15T06:46:38Z
Indexed on
2010/04/15
7:53 UTC
Read the original article
Hit count: 195
Given original codes as:
foreach($option as $name=>$value)
$array[$name] = $value;
and $name as
button[0][text], button[0][value], button[1][text], spider[0][name], ...
The result array would be
array('button[0][text]' => 'its text',
'button[0][value]' => 'its value',
'button[1][text]' => 'its text',
'spider[0][name]' => 'its name',
)
However, what i want is
array('button' => array( array('text'=>'its text', 'value'=>'its value'), // this is $array[button][0]
array('text'=>'its text') // this is $array[button][1]
),
'spider' => array( array('name'=>'its name') // this is $array[spider][0]
)
)
How could i do this? ...
© Stack Overflow or respective owner