1

i have array in this way

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

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

i need to change into

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

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

i have to change the value of qa_verified key depending on the status 0 = invalidate, 1= approve, 2=reject

i tried on array_walk, but unable to get result

any one help me on this

1 Answer 1

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

var_dump($myArray);
Sign up to request clarification or add additional context in comments.

1 Comment

I was going to post an answer with foreach, but this is much better :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.