我有这些值的数组$ aArg
array ( 0 => 'reviewed_entity', 1 => 'kiosk', )
array ( 0 => 'tripadvisor', 1 => 'tripadvisor2', )
array ( 0 => 'google', 1 => 'google2', )
array ( 0 => 'yahoo', 1 => 'yahoo2', )
我需要让它显示如下。
array ('kiosk' => array ( 'tripadvisor' => 'tripadvisor2','google' => 'google2','yahoo' => 'yahoo2',));
谢谢你们,我有不眠之夜试图获得最终合并结果,请与我分享获得理想结果的最快方法
答案 0 :(得分:0)
不确定它是否最快,但我希望你能得到理想的效果。以下代码在PHP ..
$newArr = array($aArg[0][1] => array());
$i = 0;
foreach($aArg as $arr) {
if($i) {
$newArr[$aArg[0][1]][$arr[0]] = $arr[1];
}
$i ++;
}
答案 1 :(得分:0)
您的输入数组似乎不正确。我以为它就像以下......
<?php $aArg = array(
array ( 0 => 'reviewed_entity', 1 => 'kiosk', ),
array ( 0 => 'tripadvisor', 1 => 'tripadvisor2', ),
array ( 0 => 'google', 1 => 'google2', ),
array ( 0 => 'yahoo', 1 => 'yahoo2', ));
$newArr = array($aArg[0][1] => array());
$i = 0;
foreach($aArg as $arr) {
if($i) {
$newArr[$aArg[0][1]][$arr[0]] = $arr[1];
}
$i ++;
}
var_export($newArr);