0

Got an StdObject like this

    $object = {
        "id": 1026,
        "internal_name": "mochileandoporelmundo",
        "firstName": "Letizia",
        "lastName": "Cassetta",
        "totalClicks": 64971
    }

and I want to get the keys of the objects since the object ,might have different keys at some points, I want to return something like this

$array = ['id','firstName', 'lastName','totalClicks']

Tried using array_keys() to list the keys but didn't work as expected.

1 Answers1

1

You can type cast the stdObject to an array and use array_keys:

var_dump(array_keys((array)$object));
Repox
  • 15,015
  • 8
  • 54
  • 79