MongoDB Array to normal PHP array

I have array in my MongoDB document. When im'm printing it in PHP (print_r($user->__next_action);) i got

MongoDB\Model\BSONDocument Object
(
[storage:ArrayObject:private] => Array
    (
        [text] => Sometext
    )

)

How do I get standard PHP array from this? I need

Array
(
    [text] => Sometext
)

Upvotes: 0

Views: 971

Answers (2)

guessimtoolate
guessimtoolate

Reputation: 8642

Well it’s an ArrayObject class so getArrayCopy should work.

Upvotes: 0

Valerian Pereira
Valerian Pereira

Reputation: 727

Try this

return json_decode(json_encode(iterator_to_array($user->__next_action)), TRUE);

Quick workaround to get this working.

Upvotes: 3

Related Questions