Page 1 of 1

how can split associative array and create new array?

Posted: Wed Sep 13, 2006 1:13 am
by destiny_cores
I have an array

$arr=('cat'=>'1:2:3', 'dog'=>'2:4:5');

i want to split this array and use key for new array name

ex. $cat=array('1','2','3')
$dog=array('2','4','5')


Thanks for answer and suggestion

Posted: Wed Sep 13, 2006 1:23 am
by Luke
If I understand you correctly... this should do it.

Code: Select all

$arr= array('cat' => '1:2:3', 'dog' => '2:4:5');
foreach($arr as $key => $val){
    ${$key} = explode(":", $val);
}