I want to create a function that will do this: check the object and if the property 1 is 001 then print John else if the property 2 is 002 the print Jenny but I dont know how to read the property 1 [001] and describe it as a variable.
The result that I cURL from a file:
stdClass Object
(
[id] => stdClass Object
(
[001] => John
[002] => Jenny
)
)
CodePudding user response:
Check if the id is present in your object and if it is return the name. As an example:
function get_name_from_id($obj, $id) {
return $obj->id->$id ?? false;
}