Php 将数组的特定项放在它的末尾
我想选择一个PHP数组的特定项,并将其放在数组的末尾。我的数组由未知数量的项组成(即,您事先不知道将有多少项),我想选择一个带有键Php 将数组的特定项放在它的末尾,php,arrays,Php,Arrays,我想选择一个PHP数组的特定项,并将其放在数组的末尾。我的数组由未知数量的项组成(即,您事先不知道将有多少项),我想选择一个带有键Other的项,并将其放置在数组的末尾 我用数组_diff()尝试了一些,但我无法选择其他项。我可以在foreach循环中使用Other-键选择并取消设置该项,但无法将其放置在数组的末尾。所以任何建议都很好。你能发布样本数组吗?你能发布样本数组吗?就这么简单,但我没有看到。谢谢你的回答!就这么简单,但我没有看到。谢谢你的回答! $tmp = $array['Other
Other
的项,并将其放置在数组的末尾
我用
数组_diff()
尝试了一些,但我无法选择其他
项。我可以在foreach循环中使用Other
-键选择并取消设置该项,但无法将其放置在数组的末尾。所以任何建议都很好。你能发布样本数组吗?你能发布样本数组吗?就这么简单,但我没有看到。谢谢你的回答!就这么简单,但我没有看到。谢谢你的回答!
$tmp = $array['Other'];
unset($array['Other']);
$array['Other'] = $tmp;
$array = array(
'one' => 'some value',
'other' => 'some value',
'two' => 'some value',
'three' => 'some value',
);
$other = $array['other'];
unset($array['other']);
$array['other'] = $other;
$arr = array( 'key' => 'test', 'other' => 'test2', 'key2' => 'test3' );
$arr_other = $arr['other'];
unset( $arr['other'] );
$arr['other'] = $arr_other;
print_r($arr);