1

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.

2 Answers2

0

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++;
}
K3V
  • 282
  • 6
  • 17
  • Hi, thanks i am getting it exactly. Can u pls say how can i do that in a foreach loop pls –  May 18 '15 at 06:32
  • Hi, thanks,... but, it gives me only the result `o` –  May 18 '15 at 10:16
  • Do that for each array. and for nested arrays, start a for loop with sizeof(array) as the counter limiter. – K3V May 18 '15 at 10:19
  • the sizeof method will give you the limiter value. – K3V May 19 '15 at 06:44
0

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) { }
splash58
  • 26,043
  • 3
  • 22
  • 34
  • Can you please, how can i do that in foreach loop pls –  May 18 '15 at 06:31
  • If Edu contains the data from the question, in no way, because foreach wil give yuo content of [@attributes], [School], ['SchoolLocation'].... . But if that data is var_dump of $attr in foreach, just change Edu to attr, for example `$attr['@attributes']['SchoolType']` – splash58 May 18 '15 at 07:03
  • Thanks, but i am getting only 'N' :( – AngularAngularAngular May 18 '15 at 07:11
  • Hi, Actually here is the https://eval.in/366676 it has my full array, I try to foreach the loop as it has many arrays like the one we have.. There is the problem i can't able to get the correct details there –  May 18 '15 at 08:43
  • make output by var_export($arra); and put there – splash58 May 18 '15 at 08:44
  • You mean to say i need to put var_export($arra); in the end of the page of eval i have ? –  May 18 '15 at 08:46
  • Oh, you ask me to do this to have a proper out put or wat ? –  May 18 '15 at 08:48
  • Yes! Just use var_export instead print_r or var_dump with that you make output of array – splash58 May 18 '15 at 08:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78069/discussion-between-stack-raja-and-splash58). –  May 18 '15 at 08:53