Declaring a stdClass with properties

I need to create an array of objects with properties, like this:

$var[0]->propA = “xyz”;
$var[0]->propB = “abc”;
$var[1]->propA = “123”;
$var[1]->propB = “098”;

How can I create this in a single statement? The following code does NOT work, but is the sort of thing I’m trying to do:

[php]
$var = Array(
new stdClass(
‘propA’ => ‘xyz’,
‘propB’ => ‘abc’
),
new stdClass(
‘propA’ => ‘123’,
‘propB’ => ‘098’
)
);
[/php]

Thanks for the advice!

Mike

Hey Mike,

Try this:

    $first = new stdClass;
$first->propA = 'xyz';
$first->proB = 'abc';

$second = new stdClass;
$second->propA = '123';
$second->proB = '098';

$var = Array($first,$second);

Good luck!

Regards,
developer.dex2908

Sponsor our Newsletter | Privacy Policy | Terms of Service