使用另一个数组中的索引值创建一个数组

时间:2009-05-06 16:06:25

标签: php arrays

好的,这就是我想做的事情。我有一个阵列。我想要做的是从第一个索引值的另一个数组。从下面我想要创建和数组:

   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 )
                       )
    );

最终看起来像这样:

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]
      );

有关如何实现这一目标的任何想法?我主要需要知道如何获得索引值。

3 个答案:

答案 0 :(得分:9)

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

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

答案 1 :(得分:0)

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

或者:

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

答案 2 :(得分:0)

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