2015-02-24 148 views
-1

我是新的PHP,我不知道如何從對象內部的對象然後數組中獲取數據,所以想從PHP abject獲取數據。我有使用此從php對象獲取數據

echo "<pre>"; 
var_dump($res); 
echo "</pre>"; 

得到反對數據:

object(stdClass)#1 (1) { 
    ["1"]=> 
    object(stdClass)#2 (13) { 
    ["childSemCategories"]=> 
    array(238) { 
     [0]=> 
     object(stdClass)#3 (13) { 
     ["childSemCategories"]=> 
     NULL 
     ["createdById"]=> 
     int(850) 
     ["createdDate"]=> 
     string(19) "2011-03-14T17:43:50" 
     ["displayName"]=> 
     string(27) "Abrasives & Grinding Wheels" 
     ["displayNamePath"]=> 
     string(37) "System >> Abrasives & Grinding Wheels" 
     ["entities"]=> 
     NULL 
     ["id"]=> 
     int(2210) 
     ["imagePath"]=> 
     string(37) "/images/la/s/c/t/n/ctn9mgug_1pe_0.png" 
     ["lastModifiedById"]=> 
     int(850) 
     ["lastModifiedDate"]=> 
     string(19) "2011-11-01T13:39:16" 
     ["parentId"]=> 
     int(1) 
     ["parentSemCategory"]=> 
     object(stdClass)#4 (13) { 
      ["childSemCategories"]=> 
      NULL 
      ["createdById"]=> 
      int(1) 
      ["createdDate"]=> 
      string(19) "2011-02-16T18:34:48" 
      ["displayName"]=> 
      string(6) "System" 
      ["displayNamePath"]=> 
      string(6) "System" 
      ["entities"]=> 
      NULL 
      ["id"]=> 
      int(1) 
      ["imagePath"]=> 
      string(0) "" 
      ["lastModifiedById"]=> 
      int(1) 
      ["lastModifiedDate"]=> 
      string(19) "2011-07-13T14:10:50" 
      ["parentId"]=> 
      NULL 
      ["parentSemCategory"]=> 
      NULL 
      ["status"]=> 
      string(6) "ACTIVE" 
     } 
     ["status"]=> 
     string(6) "ACTIVE" 
     } 
     [1]=> 
     object(stdClass)#5 (13) { 
     ["childSemCategories"]=> 
     NULL 
     ["createdById"]=> 
     int(850) 
     ["createdDate"]=> 
     string(19) "2011-03-14T17:46:06" 
     ["displayName"]=> 
     string(25) "Acrylic Plastics & Sheets" 
     ["displayNamePath"]=> 
     string(35) "System >> Acrylic Plastics & Sheets" 
     ["entities"]=> 
     NULL 
     ["id"]=> 
     int(2242) 
     ["imagePath"]=> 
     string(37) "/images/la/s/w/b/n/wbncmgug_1qa_0.png" 
     ["lastModifiedById"]=> 
     int(850) 
     ["lastModifiedDate"]=> 
     string(19) "2011-11-01T13:41:36" 
     ["parentId"]=> 
     int(1) 
     ["parentSemCategory"]=> 
     object(stdClass)#6 (13) { 
      ["childSemCategories"]=> 
      NULL 
      ["createdById"]=> 
      int(1) 
      ["createdDate"]=> 
      string(19) "2011-02-16T18:34:48" 
      ["displayName"]=> 
      string(6) "System" 
      ["displayNamePath"]=> 
      string(6) "System" 
      ["entities"]=> 
      NULL 
      ["id"]=> 
      int(1) 
      ["imagePath"]=> 
      string(0) "" 
      ["lastModifiedById"]=> 
      int(1) 
      ["lastModifiedDate"]=> 
      string(19) "2011-07-13T14:10:50" 
      ["parentId"]=> 
      NULL 
      ["parentSemCategory"]=> 
      NULL 
      ["status"]=> 
      string(6) "ACTIVE" 
     } 
     ["status"]=> 
     string(6) "ACTIVE" 
     } 
     [2]=> 
     object(stdClass)#7 (13) { 
     ["childSemCategories"]=> 
     NULL 
     ["createdById"]=> 
     int(2644) 
     ["createdDate"]=> 
     string(19) "2013-01-14T15:30:24" 
     ["displayName"]=> 
     string(19) "Adhesives & Fillers" 
     ["displayNamePath"]=> 
     string(29) "System >> Adhesives & Fillers" 
     ["entities"]=> 
     NULL 
     ["id"]=> 
     int(10155) 
     ["imagePath"]=> 
     NULL 
     ["lastModifiedById"]=> 
     int(2644) 
     ["lastModifiedDate"]=> 
     string(19) "2013-01-14T15:31:01" 
     ["parentId"]=> 
     int(1) 
     ["parentSemCategory"]=> 
     object(stdClass)#8 (13) { 
      ["childSemCategories"]=> 
      NULL 
      ["createdById"]=> 
      int(1) 
      ["createdDate"]=> 
      string(19) "2011-02-16T18:34:48" 
      ["displayName"]=> 
      string(6) "System" 
      ["displayNamePath"]=> 
      string(6) "System" 
      ["entities"]=> 
      NULL 
      ["id"]=> 
      int(1) 
      ["imagePath"]=> 
      string(0) "" 
      ["lastModifiedById"]=> 
      int(1) 
      ["lastModifiedDate"]=> 
      string(19) "2011-07-13T14:10:50" 
      ["parentId"]=> 
      NULL 
      ["parentSemCategory"]=> 
      NULL 
      ["status"]=> 
      string(6) "ACTIVE" 
     } 
     ["status"]=> 
     string(6) "ACTIVE" 
     } 
     [3]=> 
     object(stdClass)#9 (13) { 
     ["childSemCategories"]=> 
     NULL 
     ["createdById"]=> 
     int(1) 
     ["createdDate"]=> 
     string(19) "2011-02-16T18:34:48" 
     ["displayName"]=> 
     string(32) "Advertising, Promotions & Events" 
     ["displayNamePath"]=> 
     string(42) "System >> Advertising, Promotions & Events" 
     ["entities"]=> 
     NULL 
     ["id"]=> 
     int(2) 
     ["imagePath"]=> 
     string(35) "/images/la/s/k/0/4/k04dmgug_2_0.png" 
     ["lastModifiedById"]=> 
     int(850) 
     ["lastModifiedDate"]=> 
     string(19) "2011-11-01T13:41:57" 
     ["parentId"]=> 
     int(1) 
     ["parentSemCategory"]=> 
     object(stdClass)#10 (13) { 
      ["childSemCategories"]=> 
      NULL 
      ["createdById"]=> 
      int(1) 
      ["createdDate"]=> 
      string(19) "2011-02-16T18:34:48" 
      ["displayName"]=> 
      string(6) "System" 
      ["displayNamePath"]=> 
      string(6) "System" 
      ["entities"]=> 
      NULL 
      ["id"]=> 
      int(1) 
      ["imagePath"]=> 
      string(0) "" 
      ["lastModifiedById"]=> 
      int(1) 
      ["lastModifiedDate"]=> 
      string(19) "2011-07-13T14:10:50" 
      ["parentId"]=> 
      NULL 
      ["parentSemCategory"]=> 
      NULL 
      ["status"]=> 
      string(6) "ACTIVE" 
     } 
     ["status"]=> 
     string(6) "ACTIVE" 
     } 

我在這裏想要得到的 數據[ 「顯示名」] =>

+1

*得到PHP對象數據*這個稱號聽起來像一個PHP基礎教程的請求(以及吸血鬼磁鐵) – Rizier123 2015-02-24 08:18:18

回答

0

使用get_object_vars()函數。

$data = get_object_vars($res); // data contain array value 

可以循環$數據

foreach($data as $a){ 
    if(!is_array($a)) $a = get_object_vars($a); 
    foreach($a as $b){ 
     //loop and cek while is object value 
    } 
}