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.

3 Answers 3

9
$indexes = array_keys($whatever['items'][0]);

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

Sign up to request clarification or add additional context in comments.

3 Comments

+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: That'd just be a minor fix, though... to something like $indexes = array_keys($whatever['items'][0]);
Thank you very much ^_^ of course this will teach me to not delve into the manual a little deeper.
0
foreach($items[0] as $idx => $val)
   {
   $indexes[] = $idx;
   }

Or:

$indexes = array_keys($items[0]);

Comments

0
$result = array_keys($input['items'][0]);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.