36658

How can i take the values from this array

Question:

How can i take the SchoolType, SchoolLocation, DegreeName, StartDate and EndDate ?

I tried to take those value like this

foreach ($Edu as $attr) { $attr->SchoolType; }

But it is showing me the empty value.

Here is my Array

Array ( [@attributes] => Array ( [SchoolType] => University ) [School] => Array ( [SchoolName] => Northeastern University ) [SchoolLocation] => Northeastern [Degree] => Array ( [@attributes] => Array ( [DegreeType] => Graduate/ Undergraduate ) [IsHighestDegee] => True [DegreeName] => Bachelor [DegreeDate] => Array ( [0] => Array ( ) ) [DegreeMajor] => Array ( [Name] => Science ) [EducationDetails] => Science [DegreeMeasure] => Array ( [EducationMeasure] => Array ( [MeasureSystem] => Array ( ) [MeasureValue] => Array ( [0] => Array ( ) ) ) ) [DateofAttendance] => Array ( [StartDate] => Array ( [0] => Array ( ) ) [EndDate] => Array ( [0] => Array ( ) ) ) [EducationDescription] => Northeastern University, Boston MA Bachelor of Science, Business Administration ) )

Please help me to take the values in this single array.

Answer1:

If $Edu is array containing the data you wrote, code

var_dump($Edu['@attributes']['SchoolType']); var_dump($Edu['SchoolLocation']); var_dump($Edu['Degree']['DegreeName']); var_dump($Edu['Degree']['DateofAttendance']['StartDate']); var_dump($Edu['Degree']['DateofAttendance']['StartDate'][0]);

gives the result

string(10) "University" string(12) "Northeastern" string(8) "Bachelor" array(1) { [0]=> array(0) { } } array(0) { }

Answer2:

You will need to use index. try $attr[0][SchoolType]; keep using counter variables for the complete array.

the loop would look something like this;

$i = 0; foreach ($Edu as $attr) { $attr[$i][SchoolType]; // whatever your code has to happen. $i++; }

Recommend