I have this string
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"
}
}
How to get string which value is ‘this!!!’?
I want to save value on that place to database.
First of all, let’s get one thing straight. You don’t have a string. You have an array of objects. It is not possible (in PHP) to convert objects or arrays to strings.
If you need the value at a particular index of an array, use
$array[$index];.If you want the value of a particular attribute of an object, simply use
$object->attribute;, or if you want the return value from a function, use$object->function();.In your case:
For argument’s sake, let’s say you want to save the
valueattribute for theobjectatarray index10. The value there isSo in order to access the string value for the
valueattribute of that object, you would write:Or, if you want the string value for the
valueattribute of ALL objects, you could loop through yourarraywith aforeach