Re: Parse arrays.



On 30 Jul, 16:14, 1956col <prash.ma...@xxxxxxxxx> 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.

Is your rule for converting the "id" value to the new keys

array key = id value - 1


.



Relevant Pages

  • Re: comparing some but not all fields in lists
    ... and what's in common." ... I should compare only 3 of the 82 fields in each list. ... comparing all 82 fields as a single array element. ... cannot handle multiple keys as you want it to. ...
    (perl.beginners)
  • Re: Build an array from a text file
    ... Now that I have created my array, ... The dictionary object has a 'keys' method that returns a 0 based array ... Dim vArray As Variant ... dictionaries, so any help would be great! ...
    (microsoft.public.word.vba.general)
  • Re: Nugget - Using control references
    ... until someone decides they want to save a 3D array. ... If the users are likely to add elements to the middle of the enum, you should save and load by the enum text. ... What you can try is this - save both the string and the number. ... Unused keys are not deleted.  When the number of elements in an array is reduced, the key entries still exist in the file. ...
    (comp.lang.labview)
  • Re: hash sortieren nach werten, hash in =?ISO-8859-15?Q?popupmen?= =?ISO-8859-15?Q?=
    ... Dieses Array gibst Du bei -values an. ... Du schreibst Dir eine Funktion, die Dir die Keys ... des Hashes in der Sortierung der Werte liefert. ... values ist eine Referenz auf ein @rray, ...
    (de.comp.lang.perl.cgi)
  • Re: populating a hash with % used as the key and F string as the value
    ... > keys %lookup; ... it states one cannot push or pop a hash on page 10 ... itself is the reference to the array (read: an arrayref). ...
    (perl.beginners)