Search code examples
phpstdclass

how get value feild[ID] stdClass Object in php code


how get value feild[id] in php code

stdClass Object ( [List_inserted] => Array ( [0] => stdClass Object ( [ID] => 145001 [value] => 40 ) ) [Sucssess] => 1 [ErrorMassage] => OK ) 

Solution

  • You didn't give us a name of stdClass so I'm assuming it's $stdClass.

    $stdClass->List_inserted[0]->ID

    Let's break it down;

    stdClass Object ( [List_inserted] => Array ( [0] => stdClass Object ( [ID] => 145001 [value] => 40 ) ) [Sucssess] => 1 [ErrorMassage] => OK )

    We access objects with a -> and we access arrays with []
    The first part tells us it's an object, so it's;

    $stdClass->List_inserted

    List_inserted is an array thanks to the => Array. We can access this with [0].

    $stdClass->List_inserted[0]

    Well, List_inserted[0] is an object, thanks too [0] => stdClass Object; and you wanted to access the ID? So we need another ->

    $stdClass->List_inserted[0]->ID