开发者

How to read this PHP Array

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

Array
(
    [0] => stdClass Ob开发者_JS百科ject
        (
            [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


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


$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


You can do:

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


If array variable is $arr

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜