0

我有一个这样的数组:

1-  
    Array ( [55] => latest 
            [2] => block2 
            [3] => featured 
            [56] => News 
            [4] => portfolio 
            [57] => archive  )

另一个是由用户选择构建的,它看起来像这样:即。

2-   Array ( [0] => 56 
             [1] => 55 
             [2] => 4)

所以从数组一个中选择了3个ID,我要做的是让数组(2)上的这些值在第一个数组中重新排序,这样数组看起来像这样;

3- /*results*/ 

    Array ( [56] => News 
            [55] => latest 
            [4] => portfolio 
            [2] => block2 
            [3] => featured  
            [57] => archive  )

如果您发现我应该更改数组结构中的任何内容以获取或任何解决方案,请告诉我。

4

1 回答 1

0

像这样试试

arr1 =

Array ( [55] => latest 
        [2] => block2 
        [3] => featured 
        [56] => News 
        [4] => portfolio 
        [57] => archive  )

arr2 =

Array ( [0] => 56 
         [1] => 55 
         [2] => 4)

foreach($arr1 as $key1 => $val1)
{
    foreach($arr2 as $key2 => $val2)
    {
        if($val2 == $key1)
            $arr3[$val2] = $val1;
    }
}
print_r($arr3);

它会给你

于 2013-02-16T08:55:38.187 回答