我有这样的阵列
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= approve
,2=reject
我尝试过array_walk,但无法获得结果
任何人都可以帮助我
答案 0 :(得分:7)
$lookup = array('invalidate', 'approve', 'reject');
array_walk(
$myArray,
function(&$entry) use ($lookup) {
$entry->qa_verified = $lookup[$entry->qa_verified];
}
);
var_dump($myArray);