E
E
enrike2015-02-15 05:06:18
PHP
enrike, 2015-02-15 05:06:18

How to extract the desired array from json?

I have a task: I
need to display information about education (degree, endDate (year), fieldOfStudy, schoolName, startDate (year)) and the names of all skills (skills-> name). Tried different things but couldn't find a solution.
Thank you in advance!

object(stdClass)#2 (10) {
  ["educations"]=>
  object(stdClass)#3 (2) {
    ["_total"]=>
    int(2)
    ["values"]=>
    array(2) {
      [0]=>
      object(stdClass)#4 (6) {
        ["degree"]=>
        string(17) "Bachelor's degree"
        ["endDate"]=>
        object(stdClass)#5 (1) {
          ["year"]=>
          int(2016)
        }
        ["fieldOfStudy"]=>
        string(20) "BSc Engineering"
        ["id"]=>
        int(131239888)
        ["schoolName"]=>
        string(16) "Test University"
        ["startDate"]=>
        object(stdClass)#6 (1) {
          ["year"]=>
          int(2012)
        }
      }
      [1]=>
      object(stdClass)#7 (4) {
        ["endDate"]=>
        object(stdClass)#8 (1) {
          ["year"]=>
          int(2012)
        }
        ["id"]=>
        int(115023711)
        ["schoolName"]=>
        string(32) "Test High School"
        ["startDate"]=>
        object(stdClass)#9 (1) {
          ["year"]=>
          int(2007)
        }
      }
    }
  }
  ["skills"]=>
  object(stdClass)#15 (2) {
    ["_total"]=>
    int(4)
    ["values"]=>
    array(4) {
      [0]=>
      object(stdClass)#16 (2) {
        ["id"]=>
        int(1)
        ["skill"]=>
        object(stdClass)#17 (1) {
          ["name"]=>
          string(4) "HTML"
        }
      }
      [1]=>
      object(stdClass)#18 (2) {
        ["id"]=>
        int(4)
        ["skill"]=>
        object(stdClass)#19 (1) {
          ["name"]=>
          string(3) "CSS"
        }
      }
      [2]=>
      object(stdClass)#20 (2) {
        ["id"]=>
        int(8)
        ["skill"]=>
        object(stdClass)#21 (1) {
          ["name"]=>
          string(5) "MySQL"
        }
      }
      [3]=>
      object(stdClass)#22 (2) {
        ["id"]=>
        int(22)
        ["skill"]=>
        object(stdClass)#23 (1) {
          ["name"]=>
          string(15) "Web Development"
        }
      }
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-02-15
@enrike

$degree = $object->educations->values[0]->degree;
$skill = $object->skills->values[0]->skill->name;
How to sort through all the skills / diplomas, I hope you figure it out yourself.
PS maybe I screwed up somewhere: the formatting of the example is hell.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question