stdClass object and foreach loops

It is an array, so you can loop over it easily using foreach: foreach ($result->GetIncomingMessagesResult->SMSIncomingMessage as $message) { echo $message->Reference; } However it is worth noting that PHP’s SoapClient by default appears to return arrays as a PHP array only when there is more than one value in the array – if there is only … Read more

PHP: Count a stdClass object

The problem is that count is intended to count the indexes in an array, not the properties on an object, (unless it’s a custom object that implements the Countable interface). Try casting the object, like below, as an array and seeing if that helps. $total = count((array)$obj); Simply casting an object as an array won’t … Read more

How to convert an array into an object using stdClass() [duplicate]

You just add this code $clasa = (object) array( ‘e1’ => array(‘nume’ => ‘Nitu’, ‘prenume’ => ‘Andrei’, ‘sex’ => ‘m’, ‘varsta’ => 23), ‘e2’ => array(‘nume’ => ‘Nae’, ‘prenume’ => ‘Ionel’, ‘sex’ => ‘m’, ‘varsta’ => 27), ‘e3’ => array(‘nume’ => ‘Noman’, ‘prenume’ => ‘Alice’, ‘sex’ => ‘f’, ‘varsta’ => 22), ‘e4’ => array(‘nume’ => … Read more

What is stdClass in PHP?

stdClass is just a generic ’empty’ class that’s used when casting other types to objects. Despite what the other two answers say, stdClass is not the base class for objects in PHP. This can be demonstrated fairly easily: class Foo{} $foo = new Foo(); echo ($foo instanceof stdClass)?’Y’:’N’; // outputs ‘N’ I don’t believe there’s … Read more