Reputation: 4050
I have a set of data that looks like this
object(stdClass)#5 (39) { ["id"]=> int(125273716) ["status"]=> object(stdClass)#6 (18) { ["retweeted"]=> ["text"]=> string(28) "1234567" } ["is_translator"]=> bool(false)}
How can I get the ["text"]? I've removed some parts of the data because it's too long. All I want is the ['text'] parameter. Thanks
Upvotes: 1
Views: 93
Reputation: 1980
Function to Convert stdClass Objects to Multidimensional Arrays
<?php
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
?>
Use:
<?php
echo '<pre>';
var_dump(objectToArray($object));
echo '</pre>';
Upvotes: 2
Reputation: 28753
object(stdClass)#5 (39) { ["id"]=> int(125273716) ["status"]=> object(stdClass)#6 (18) { ["retweeted"]=> ["text"]=> string(28) "1234567" } ["is_translator"]=> bool(false)}
You can try as put $res as
$res = $result->status->text;
echo $res;
Upvotes: 0