Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过保留另一个数组对数组值的键进行排序_Php_Arrays_Array Merge - Fatal编程技术网

Php 通过保留另一个数组对数组值的键进行排序

Php 通过保留另一个数组对数组值的键进行排序,php,arrays,array-merge,Php,Arrays,Array Merge,我需要比较另一个数组的数组值。我做了一些事情,但我不知道如何保存钥匙 $razeni=Array(0=>1,1=>2,2=>0,3=>3); $myservices=Array(0=>"text0", 1=>"text1", 2=>"text2", 3=>"text3", 4=>"text4", 5=>"text5", 6=>"text6", 7=>"text7"); 现在比较 foreach ($razeni as $k

我需要比较另一个数组的数组值。我做了一些事情,但我不知道如何保存钥匙

$razeni=Array(0=>1,1=>2,2=>0,3=>3);
$myservices=Array(0=>"text0", 1=>"text1", 2=>"text2", 3=>"text3", 4=>"text4", 5=>"text5", 6=>"text6", 7=>"text7");
现在比较

foreach ($razeni as $key=>$value) {
  $myservices_[$value] = $myservices[$value];
  unset($myservices[$value]);    
}

if (isset($myservices_))
{
  $myservices = array_merge($myservices_, $myservices);
}
结果:

Array
(
    [0] => text1
    [1] => text2
    [2] => text0
    [3] => text3
    [4] => text4
    [5] => text5
    [6] => text6
    [7] => text7
)
但我需要这个结果

Array
(
    [1] => text1
    [2] => text2
    [0] => text0
    [3] => text3
    [4] => text4
    [5] => text5
    [6] => text6
    [7] => text7
)

而不是使用数组合并

如果要附加数组元素 从第二个数组到第一个数组 数组,而不覆盖 第一个数组中的元素,而不是 重新编制索引时,请使用+数组联合 接线员


而不是使用数组合并

如果要附加数组元素 从第二个数组到第一个数组 数组,而不覆盖 第一个数组中的元素,而不是 重新编制索引时,请使用+数组联合 接线员

$myservices = $myservices_ + $myservices;