tags:

views:

50

answers:

4

Hello,

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

A: 

$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

Lekensteyn
+1  A: 

You can do:

foreach($array as $arr) {
 echo $arr->status;
}
codaddict
+1  A: 

If array variable is $arr

$arr[0]->status;
$arr[1]->status;
NAVEED
+5  A: 

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;
}
Chacha102