how to genrate nessted array in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ali_engr
Forum Newbie
Posts: 12
Joined: Thu Jun 21, 2007 8:08 am

how to genrate nessted array in php

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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');
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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]
Post Reply