我有这个数组:
$request = array(
'method' => 'Document.create',
'params' => Array (
'document' => Array ( SOME DATA
),
'thirdaddress' => Array ( SOME DATA
),
'row' => Array (
'1' => Array ( SOME DATA
),
'2' => Array ( SOME DATA
),
'4' => Array ( SOME DATA
),
)
)
);
我想在“2”和“4”键之间“注入”
'3' => Array ( SOME DATA
),
我想用这样的结构注入:
$secondArray = array(
'params'=>Array(
'row'=> Array(
'3' => Array ( SOME DATA
),
)
)
);
我试过这个:
1. $request['params']['row']['3']=$secondArray;
2. $request = array_merge($request,$secondArray);
3. $request = array_merge_recursive($request,$secondArray);
ksort也不起作用..我的行被困在最后一个位置.. 我做了一个
if(STATEMENT){
//$request = array_merge_recursive($request,$secondArray;
//$request['params']['row']['3']=$secondArray['params']['row']['3'];
$request['params']['row']['3']=$secondArray;
ksort($request);
}
die(dump($request));
我哪里错了? 感谢。
答案 0 :(得分:1)
如果只是插入它,这应该有效 -
$request['params']['row']['3'] = Array(SOME DATA);
//This sorts the "row" keys -
ksort($request['params']['row'], SORT_NUMERIC)
答案 1 :(得分:1)
<?php
$request = array(
'method' => 'Document.create',
'params' => Array (
'document' => Array ( SOME DATA
),
'thirdaddress' => Array ( SOME DATA
),
'row' => Array (
'1' => Array ( SOME DATA
),
'2' => Array ( SOME DATA
),
'4' => Array ( SOME DATA
),
)
)
);
$secondArray = array(
'params'=>Array(
'row'=> Array(
'3' => Array ('foo' => 'bar'),
)
)
);
$request = array_merge_recursive($request, $secondArray)
答案 2 :(得分:0)
点数1.你几乎是好的,你只需要这个改变 而不是:
$secondArray = array(
'params'=>Array(
'row'=> Array(
'3' => Array ( SOME DATA
),
)
)
);
试试这个:
$secondArray = array(SOME DATA);