2012-08-22 145 views
1

的Retrive數據我有一組數據,看起來像這樣PHP:從一組陣列

object(stdClass)#5 (39) { ["id"]=> int(125273716) ["status"]=> object(stdClass)#6 (18) { ["retweeted"]=> ["text"]=> string(28) "1234567" } ["is_translator"]=> bool(false)} 

我怎樣才能獲得[「文本」]我已經刪除了數據的某些部分,因爲它太長。所有我想要的是[「文本」]參數。感謝

+0

'$ TXT = $ foo.status.text' –

回答

2

函數將轉換stdClass的對象,以多維數組

<?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; 
     } 
    } 
?> 

用途:

<?php 
echo '<pre>'; 
var_dump(objectToArray($object)); 
echo '</pre>'; 

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

4

嘗試這種情況:

$object->status->text 
+0

感謝它工作:) – rksh

1

它是一個對象

echo $result->status->text; 
+0

感謝它的工作:) – rksh

0

對象(stdClass的)#5(39){[ 「ID」] => INT(125273716)[ 「狀態」 ] => object(stdClass)#6(18){[「retweeted」] => [「text」] => string(28)「1234567」} [「is_translator」] => bool(false)}

您可以嘗試爲put $水庫作爲

$res = $result->status->text; 
echo $res;