R
R
Roquefort2018-04-11 13:31:48
PHP
Roquefort, 2018-04-11 13:31:48

How to iterate over an object of objects?

From the API comes a stdClass object with nested stdClass objects in which more objects are also nested, etc. I need to validate this response. There are a number of properties that must be of a certain format. These properties are at different levels and the name of the property can be repeated in different objects.
What can you advise? I'm not asking you to throw out the code directly to me. But to give direction in the direction of which algorithms to look at?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanovskiy, 2018-04-11
@Sanovskiy

$a = new stdClass();
$a->foo = 1;
$a->bar = 2;
$a->baz = 3;
foreach ( (array) $a as $val){
echo $val;
}
Dig towards type conversions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question