user1362020
user1362020

Reputation: 17

Read stdClass Object in php

When I send data from ASP.net to PHP, I want to read data using SoapClient like this:

stdClass Object ( [HelloWorldResult] => stdClass Object ( [string] => Array ( [0] => 0 [1] => 4546330305913 [2] => 1395/11/20 [3] => 0 ) ) ) 

How do I access the 1st element of the array (i.e. Array[0])?

Upvotes: 1

Views: 1418

Answers (1)

JazZ
JazZ

Reputation: 4579

You have to read your object.

It says that it's a standard object who contains a standard object who contains an array. So, first tell about first object than second object to end with the array's name followed by key you want to get :

$some_obj->HelloWorldResult->string[0]

For an example :

$some_obj = new stdClass();
$some_obj->HelloWorldResult = new stdClass();
$some_obj->HelloWorldResult->string = array(
    0,
    4546330305913,
    "1395/11/20",
    0
);

print_r($some_obj);

Output :

stdClass Object
(
    [HelloWorldResult] => stdClass Object
    (
        [string] => Array
        (
            [0] => 0
            [1] => 4546330305913
            [2] => 1395/11/20
            [3] => 0
        )
    )
)

Then to access some value :

var_dump($some_obj->HelloWorldResult->string[0]);

Output :

int(0)

Upvotes: 1

Related Questions