tags:

views:

170

answers:

3

OK here is what I would like to do. I have an array. What i want to do is make another array of the index values from the first one. Take the below I want to create and array from this :

   Array ( 
    [identifier] => ID 
    [label] => HouseNum 
    [items] => Array ( 
                      [0] => Array ( 
                                    [ID] => 1 
                                    [HouseNum] => 17  
                                    [AptNum] => 
                                    [Street] => birch glen dr 
                                    [City] => Clifton Park 
                                    [State] => NY [Zip5] =>   
                                    [EID] => E083223 
                                    [RequestDate] => 02/05/09 
                                    [Status] => In-Qeue 
                                    [DateCompleted] => 
                                    [CompletedBy] =>  
                                    [ContactName] => Suzy Q 
                                    [ContactNumber] => 555-867-5309 
                                    [ContactTime] => 9-9 )
                       )
    );

That will end up looking like this :

Array(
      [0] => [ID] 
      [1] => [HouseNum] 
      [2] => [AptNum]
      [3] => [Street] 
      [4] => [City]
      [5] => [State] 
      [6] => [Zip5]  
      [7] => [EID] 
      [8] => [RequestDate]
      [9] => [Status]
      [10] => [DateCompleted]
      [11] => [CompletedBy]  
      [12] => [ContactName] 
      [13] => [ContactNumber]
      [14] => [ContactTime]
      );

Any thoughts on how to achieve this ? I mostly need to know how to get just the index values.

A: 
foreach($items[0] as $idx => $val)
   {
   $indexes[] = $idx;
   }

Or:

$indexes = array_keys($items[0]);
BrynJ
+9  A: 
$indexes = array_keys($whatever['items'][0]);

http://us.php.net/manual/en/function.array-keys.php

MiffTheFox
+1 for using a native function. But one little mistake: `items` is just an element of the given variable and not the variable itself.
Gumbo
@Gumbo: That'd just be a minor fix, though... to something like $indexes = array_keys($whatever['items'][0]);
R. Bemrose
Thank you very much ^_^ of course this will teach me to not delve into the manual a little deeper.
Arasoi
A: 
$result = array_keys($input['items'][0]);
dr Hannibal Lecter