PHP Print keys from an object?

user723220 picture user723220 · Apr 27, 2011 · Viewed 69.8k times · Source

I have an object BIRD and then there is [0] through [10] and each number has a subheading like "bug" or "beetle" or "gnat" and a value for each of those.

I want to print

BIRD 
    [0]
       bug = > value 

I can't find out how to do this anywhere - there is talk of PUBLIC and PRIVATE and CLASS and that's where I fall off

Answer

brenjt picture brenjt · Jan 18, 2013

You could easily do it by type casting the object:

$keys = array_keys((array)$BIRD);