在php中更改数组的值

时间:2013-04-10 06:39:29

标签: php codeigniter

我有这样的阵列

    Array
    (
        [0] => stdClass Object
            (
                [qa_verified] => 0          
            )

        [1] => stdClass Object
            (
                [qa_verified] => 1               
            )
        [2] => stdClass Object
            (
                [qa_verified] => 2               
            )
)

我需要换成

Array
(
    [0] => stdClass Object
        (
            [qa_verified] => invalidate          
        )

    [1] => stdClass Object
        (
            [qa_verified] => approve               
        )
    [2] => stdClass Object
        (
            [qa_verified] => reject               
        )
)

我必须根据状态更改qa_verified密钥的值 0 = invalidate1= approve2=reject

我尝试过array_walk,但无法获得结果

任何人都可以帮助我

1 个答案:

答案 0 :(得分:7)

$lookup = array('invalidate', 'approve', 'reject');
array_walk(
    $myArray,
    function(&$entry) use ($lookup) {
        $entry->qa_verified = $lookup[$entry->qa_verified];
    }
);

var_dump($myArray);