2

I juste want to know how to read the value "status" in this PHP array:

Array
(
    [0] => stdClass Object
        (
            [smsId] => 10124
            [numberFrom] => +000
            [numberTo] => +000
            [status] => waiting
            [date] => 20100825184048
            [message] => ACK/
            [text] => Test
        )
    [1] => stdClass Object
        (
            [smsId] => 10125
            [numberFrom] => +000
            [numberTo] => +000
            [status] => waiting
            [date] => 20100825184049
            [message] => ACK/
            [text] => Test 2
        )

)

Thanks

1

4 Answers 4

6

Basically you have an array of objects. So you have to use a combination of array and object syntax to get your value:

$array[0]->status;

this breaks down into:

$object = $array[0]; // Array Syntax
$status = $object->status; // Object Syntax
$status = $array[0]->status; // Combined Array & Object Syntax

If you need to access each status in a loop, you do something like:

foreach($array as $obj){
    $status = $obj->status;
}
Sign up to request clarification or add additional context in comments.

Comments

1

$arr is the array you've got there.

for($i=0; $i<count($arr); $i++){
   echo $arr[$i]->status;
}

Please take a look in the PHP Manual

Comments

1

You can do:

foreach($array as $arr) {
 echo $arr->status;
}

Comments

1

If array variable is $arr

$arr[0]->status;
$arr[1]->status;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.