Omar Taha
Omar Taha

Reputation: 265

Define an stdClass object and put array into it

I have a PHP array, and I want to define an stdClass object, and put the array into it, I want something like this:

my array is:

   Array ( [0] => stdClass Object ( [subitem] => stdClass Object ( [item] => stdClass        
   Object ( [Label] => Customer Name [value] => value ) ) )

I want it to become:

   stdClass Object (
           Array ( [0] => stdClass Object ( [subitem] => stdClass Object ( [item] => 
          stdClass Object ( [Label] => Customer Name [value] => Ministry of Finance /  
          Ramallah ) ) ) 
     )

Any help?

Upvotes: 0

Views: 258

Answers (1)

krun
krun

Reputation: 790

You cannot assing array to class you can assing it to class variable.

for example

$yourArray = array();
$yourObject = new \stdClass();
$yourObject->yourVar = $yourArray;

But i do not know if it is what you want achieve?

Upvotes: 1

Related Questions