好的,这就是我想做的事情。我有一个阵列。我想要做的是从第一个索引值的另一个数组。从下面我想要创建和数组:
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]
);
有关如何实现这一目标的任何想法?我主要需要知道如何获得索引值。
答案 0 :(得分:9)
$indexes = array_keys($whatever['items'][0]);
答案 1 :(得分:0)
foreach($items[0] as $idx => $val)
{
$indexes[] = $idx;
}
或者:
$indexes = array_keys($items[0]);
答案 2 :(得分:0)
$result = array_keys($input['items'][0]);