homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Convert associative big array to small array in php
Convert associative big array to small array in php
rohankanhai




msg:4632929
 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




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

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved