Page 1 of 1

how to genrate nessted array in php

Posted: Tue Jul 24, 2007 2:11 am
by ali_engr
I want to generate nested a array in loop? like parents & childes relations in nested array

any idea, [s]plz[/s] please guide me.

thanks
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Tue Jul 24, 2007 3:53 am
by Jenk
you can start by
a) not posting in the General Discussion forum, where the description is:
This forum is not for asking programming related questions.
b) posting the PHP Code forum.
c) Posting the code you have already got.
d) Search before asking.

Posted: Tue Jul 24, 2007 5:33 am
by s.dot

Code: Select all

$array = array();
$array['parents'] = array('bob', 'susie', 'joe');

$array['parents']['bob'] = array('kid1', 'kid2', 'kid3');
$array['parents']['susie'] = array();
$array['parents']['joe'] = array('kid4', 'kid5');

Posted: Tue Jul 24, 2007 6:13 am
by feyd
This was posted as a new thread.
ali_engr wrote:feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i have a parent array

i am looping that parent array & want to add child array in the parent array but it does not work
code is like

Code: Select all

$grandparentarray= array('pid'=>0, 'id'=>1, 'name'=>'GrandFather', 'childs'=>array() );

$parentarray= array('pid'=>1, 'id'=>2, 'name'=>'Father', 'childs'=>array() );

foreach($grandparentarray as  $arr)
{

   $arr['childs'][]= $parentarray;

}
i want to see result like

Code: Select all

array(
           'pid'=>0, 'id'=>1, 
           'name'=>'GrandFather', 
           'childs'=>array(
                                   array('pid'=>1, 
                                             'id'=>2, 
                                              'name'=>'Father', 
                                               'childs'=>array()
                                  )
       );
code looks ok, but does get the result, child array is not pushed into parent aarray in foreach loop


Please guide me,


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/quote]