rksh
rksh

Reputation: 4050

PHP : Retrive data from a set of arrays

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

Answers (4)

Julien
Julien

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

Source: http://www.if-not-true-then-false.com/2009/php-tip-convert-stdclass-object-to-multidimensional-array-and-convert-multidimensional-array-to-stdclass-object/

Upvotes: 2

GautamD31
GautamD31

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

Mihai Iorga
Mihai Iorga

Reputation: 39724

It's an Object

echo $result->status->text;

Upvotes: 1

PiTheNumber
PiTheNumber

Reputation: 23552

Try this:

$object->status->text

Upvotes: 4

Related Questions