Get object properties in an array?

I have several arrays ($ result) in which there are objects. The array was returned from a function (made by someone that I cannot communicate with now).

When I test an array using print_r ($ result [0]), it has built-in objects.

ABC Object ( 
    [p1] => P1 Object ( 
        [p1-1] => P1_property1 
        [p1-2] => P1_property2 
        [p1-3] => P1_property3
    ) 
    [p2] => ABC_property2 
    [p3] => ABC_property3 
    [p4] => ABC_property4
)

How can I get strings "P1_property1"before "P1_property3"and "ABC_property2"before "ABC_property4"?

I am new to PHP, waiting for help!

+3
source share
3 answers

It looks like you want one that will return an array of available properties. get_object_vars()

class foo {
  public $bar = "foo";
  private $bor = "fizz";
}

$properties = get_object_vars( new foo() );

print_r( $properties );

What are the findings:

Array
(
    [bar] => foo
)
+5
source

Try using this to find out what the contents of these variables are:

var_dump(get_object_vars($result[0]));
+1
source
This function return all the properties in a class

function get_object_public_vars($object) {
    return get_object_vars($object);
}
0
source

All Articles