array_flip某些键

时间:2009-04-03 20:06:10

标签: php arrays

用键2翻转键1的好方法是什么?

// original
Array
(
    [0] => Text1
    [1] => World
    [2] => Hello
)

// after

Array
(
    [0] => Text1
    [1] => Hello
    [2] => World
)

任何线索。感谢

2 个答案:

答案 0 :(得分:4)

如果这很简单,

$tmp = $array[1];
$array[1] = $array[2];
$array[2] = $tmp;

答案 1 :(得分:0)

$A = array("Text1", "Hello", "World");
$tmp = $A[2];
$A[2] = $A[1];
$A[1] = $tmp;