By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Parse arrays.

P: n/a
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.

Jul 30 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 30 Jul, 16:14, 1956col <prash.ma...@gmail.comwrote:
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.
Is your rule for converting the "id" value to the new keys

array key = id value - 1
Jul 30 '07 #2

P: n/a
On Jul 30, 11:14 am, 1956col <prash.ma...@gmail.comwrote:
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.
something like this...

$options = array();
$kids = array();
foreach ($c as $cc) {
foreach ($cc['children'] as $key =$value) {
$k = $key - 1;
$kids[] = array($k =$value);
array_push($cc['name'] =$kids);
}
}

it depends on the bigger picture of your data and how it's formatted.

Jul 30 '07 #3

P: n/a
Rik
On Mon, 30 Jul 2007 17:14:47 +0200, 1956col <pr*********@gmail.comwrote:
hi all,
have a simple problem,
<snip>

Please don't multipost, I see you've got answers in different groups, save
people the trouble answering something that is allready answered.

--
Rik Wasmus
Jul 31 '07 #4

P: n/a
On Jul 31, 5:11 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Mon, 30 Jul 2007 17:14:47 +0200, 1956col <prash.ma...@gmail.comwrote:
hi all,
have a simple problem,

<snip>

Please don't multipost, I see you've got answers in different groups, save
people the trouble answering something that is allready answered.

--
Rik Wasmus
Thabks for that one ELINTPimp
good solution ,

but i tried foreach inside foreach and its working absolutly fine,
thanks once again
Jul 31 '07 #5

P: n/a
On Jul 31, 5:11 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Mon, 30 Jul 2007 17:14:47 +0200, 1956col <prash.ma...@gmail.comwrote:
hi all,
have a simple problem,

<snip>

Please don't multipost, I see you've got answers in different groups, save
people the trouble answering something that is allready answered.

--
Rik Wasmus
yup
sory for that ,
i m a newbie .
won't happen next time.

Jul 31 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.