3

我如何从这个数组(stdClass)php中获取数据?

Array
(
    [0] => stdClass Object
        (
            [id] => 4
            [programs] => FireFox
            [version] => 4.00
            [type] => Browsers
            [description] => fdmkfdsf,sdfdsfdsfdsf
dfdsf
sd
f
dsf
ds
f
            [views] => 2
            [serial] => 434343-343434-3434-c
        )

)

当我尝试使用 foreach 获取它时,我得到了那个错误

#
A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: views/results.php

Line Number: 2

我怎样才能得到程序的数据(例如 FireFox)?

4

2 回答 2

3
$data = (your data);

echo $data[0]->programs;
于 2011-04-03T21:54:46.747 回答
0

如果您想将其$data用作数组,则应将其更改为

$val =  json_decode(json_encode($data),true);//to convert stdClass object into array
echo"<pre>";
print_r($val)  //print the value of $val

echo $val['program'];  //Now you can use it as array in your code
于 2016-03-10T17:10:25.533 回答