Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Convert associative big array to small array in php

Convert associative big array to small array in php

     

rohankanhai

11:05 pm on Dec 22, 2013 (gmt 0)



Hello,

-> I have an array like this,

array(
name => 'acc',
attr => Array(
id => 32
),
children => Array(
Array(
name => 'name',
attr => Array(),
children => Array(
'test'
),
),
Array(
name => 'cats',
attr => Array(),
children=>Array(
Array(
name => 'cat',
attr => Array(
id => 43
),
children => Array(
Array(
name => 'url',
attr => Array(),
children => Array(
'http://www.google.com'
)
)
)
),
Array(
name => 'cat',
attr => Array(
id => 87
),
children => Array(
Array(
name => 'url',
attr => Array(),
children => Array(
'http://www.yahoo.com'
)
)
)
)
)
)
)
);

I want this array to be like below array,

array
(
'acc' => Array
(
'id' => 32,
'name' => 'test',
'cats' => Array
(
'cat' => Array
(
'0' => Array
(
'id' => 43,
'url' => 'http://www.google.com/'
),
'1' => Array
(
'id' => 87,
'url' => 'http://www.yahoo.com'
)
)
)
)
);

Any help would be appreciate.

penders

11:13 pm on Dec 30, 2013 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Have you managed to get anywhere with this? What code/approach have you tried?

How have you output your array data? It would be useful, for anyone attempting to tackle your problem, to output valid PHP (var_export), which your target array appears to be pretty close to. But your source data seems to be some hybrid var dump?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month