Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中的std类_Php_Arrays_Std - Fatal编程技术网

php中的std类

php中的std类,php,arrays,std,Php,Arrays,Std,我有这根绳子 array(8) { [2]=> object(stdClass)#871 (2) { ["access"]=> int(0) ["value"]=> string(4) "Male" } [3]=> object(stdClass)#872 (2) { ["access"]=> int(0)

我有这根绳子

array(8) {
    [2]=> object(stdClass)#871 (2) {
        ["access"]=> int(0)
        ["value"]=> string(4) "Male"
    }
    [3]=> object(stdClass)#872 (2) {
        ["access"]=> int(0)
        ["value"]=> string(2) "21"
    }
    [4]=> object(stdClass)#874 (2) {
        ["access"]=> int(0)
        ["value"]=> string(4) "sdad"
    }
    [10]=> object(stdClass)#861 (2) {
        ["access"]=> int(0)
        ["value"]=> string(0) ""
    }
    [11]=> object(stdClass)#873 (2) {
        ["access"]=> int(0)
        ["value"]=> string(11) "fds"
    }
    [17]=> object(stdClass)#875 (2) {
        ["access"]=> int(0)
        ["value"]=> string(11) "aaa"
    }
    [19]=> object(stdClass)#876 (2) {
        ["access"]=> int(0)
        ["value"]=> string(4) "this!!!"
    } [29]=> object(stdClass)#878 (2) {
        ["access"]=> int(0)
        ["value"]=> string(3) "sda"
    }
}
如何获取值为“this!!!”的字符串?
我想把那个地方的价值保存到数据库中。

首先,让我们弄清楚一件事。你没有绳子。您有一个对象数组。(在PHP中)无法将对象或数组转换为字符串

如果需要数组特定索引处的值,请使用
$array[$index]

如果需要对象的特定属性的值,只需使用
$object->attribute
,或者如果希望从函数返回值,请使用
$object->function()

在您的情况下:

为了便于讨论,假设您希望将
对象的
属性保存在
数组索引
10处。这里的价值是

[10]=> object(stdClass)#861 (2) {
    ["access"]=> int(0)
    ["value"]=> string(0) ""
}
因此,为了访问该对象的
value
属性的字符串值,您可以编写:

$val = $array[10]->value;
或者,如果需要所有对象的
value
属性的字符串值,可以使用
foreach

foreach($array as $obj) {
    $val = $obj->value;
    $access = $obj->access;

    // do something with $val and/or $access
}

你没有绳子。您有一个对象数组。