-6

我需要将数组项的顺序更改为预定义的顺序。

原始数组是

$order = array(3136,3121,3147,3125);

Array
(
    [3121] => Array
        (
            [0] => 311
            [1] => 311>
            [2] => First Level
        )

    [3125] => Array
        (
            [0] => 312
            [1] => 312>
            [2] => Ids
        )

    [3136] => Array
        (
            [0] => 313
            [1] => 313>
            [2] => Insurance
        )

    [3147] => Array
        (
            [0] => 314
            [1] => 314>
            [2] => Property
        )
)

需要像下面这样生成,

Array
(
    [3136] => Array
        (
            [0] => 313
            [1] => 313>
            [2] => Insurance
        )
    [3121] => Array
        (
            [0] => 311
            [1] => 311>
            [2] => First Level
        )
    [3147] => Array
        (
            [0] => 314
            [1] => 314>
            [2] => Property
        )
    [3125] => Array
        (
            [0] => 312
            [1] => 312>
            [2] => Ids
        )

)

base 将是数组元素的键,在 3136 元素之后 3121 将被推送然后 3147 等等

4

1 回答 1

2

只是一个猜测:

$order = array(3136,3121,3147);
$new_arr =array();
foreach ($order as $key){
    if ($old_array[$key])
        $new_arr[$key]=$old_array[$key];
}
于 2012-05-28T07:28:38.927 回答