Parse arrays.

hi all,
have a simple problem,
my array is :-

$c = array(
"2" => array(
"id" => "2",
"name" => "Sport",
"children" => array(
"4" => array(
"id" => "4",
"name" =>
"Archery",
"children" =>
"",
),

"5" => array(
"id" => "5",
"name" =>
"Badminton",
"children" =>
"",
),
),
),

);


and i want to convert this to

$options = array(
'Sports' =>array(
'3' => 'Archery',
'4' => 'Badminton',
),
);

Where 3 & 4 are the keys foe Archey & Badminton resp.
I am a newbie to PHP
getting so many problems solving this,
Any help appriciated.
prash.marne [ Mo, 30 Juli 2007 17:13 ] [ ID #1782091 ]

Re: Parse arrays.

On Jul 31, 1:13 am, 1956col <prash.ma... [at] gmail.com> wrote:
> hi all,
> have a simple problem,
> my array is :-
>
> $c = array(
> "2" => array(
> "id" => "2",
> "name" => "Sport",
> "children" => array(
> "4" => array(
> "id" => "4",
> "name" =>
> "Archery",
> "children" =>
> "",
> ),
>
> "5" => array(
> "id" => "5",
> "name" =>
> "Badminton",
> "children" =>
> "",
> ),
> ),
> ),
>
> );
>
> and i want to convert this to
>
> $options = array(
> 'Sports' =>array(
> '3' => 'Archery',
> '4' => 'Badminton',
> ),
> );
>
> Where 3 & 4 are the keys foe Archey & Badminton resp.
> I am a newbie to PHP
> getting so many problems solving this,
> Any help appriciated.


Do a nested foreach.
Here's a guideline of the code.

// More code here
foreach($c as $activity) {
// More code here
foreach($activity as $id=>$child) {
// More code here
}
}
print_r($options);



Hendri Kurniawan
Hendri Kurniawan [ Di, 31 Juli 2007 01:03 ] [ ID #1783002 ]
PHP » alt.php » Parse arrays.

Vorheriges Thema: SEARCH SCRIPT HELP!
Nächstes Thema: session and subdomain