1

我以这种方式有数组

    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 = invalidate,,1= approve2=reject

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

任何人都可以帮助我

4

1 回答 1

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

var_dump($myArray);
于 2013-04-10T06:44:26.870 回答