1

I have a array of objects like this one:

Array
(
    [0] => stdClass Object
        (
            [art_id] => 76
            [title] => whatever
        )

    [1] => stdClass Object
        (
            [art_id] => 216
            [title] => blabla
        )

)

Can I somehow get a array with all art_id's from it, without having to iterate it?

(like array(76, 216))

1
  • csn you please clarify why you dont want to iterate it or at least explain what iterating means to you in the context of your question? Commented Jun 8, 2011 at 12:48

1 Answer 1

6
function getArtId($obj)
{
    return $obj->art_id;
}

$b = array_map("getArtId", $a);
print_r($b);

This is indirectly an iteration, but you do not need to write code for the loop yourself.

Sign up to request clarification or add additional context in comments.

Comments

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.