Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new on php and i dont know how to get data from object inside object then array and after that data so want to get data from php abject. i have use this

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

to get objected data as:

 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"
      }

Here i am want to get data of ["displayName"]=>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
127 views
Welcome To Ask or Share your Answers For Others

1 Answer

use get_object_vars() function.

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

you can looping $data

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...