How can i get particular fields in the array using foreach

前端 未结 2 1411
不知归路
不知归路 2020-12-22 08:24

I wanted to take the fields such as School Type, Name, Location, Details, Degreemjor, Education details, Start and End Date

How can i do this using the foreach loop

相关标签:
2条回答
  • 2020-12-22 09:03

    I'm an idiot, it didn't click that that was XML. Okay, so your array appears to be an array of schools/institutions from a resume, correct? Just follow the XML hierarchy to reach each node that you care about.

    foreach ($nodes as $node) {
        echo "Type: " . $node->attributes()['SchoolType'] . "\n";
        echo "Name: " . $node->School->SchoolName . "\n";
        echo "Location: " . $node->SchoolLocation . "\n";
        echo "Degree name: " . $node->Degree->DegreeName . "\n";
        // etc
    }
    
    0 讨论(0)
  • 2020-12-22 09:09

    Have a look at SimpleXMLElement::attributes

    I think you can get the element like

    $url = 'http://recruitplushrxmlapidemo.onlineresumeparser.com/hrxml/153Melanie%20R.%20Mather%20Mills.xml';
    
    $sxml = simplexml_load_file($url);
    
    foreach($sxml->StructuredXMLResume->EducationHistory->SchoolOrInstitution as $key => $value){
    
        echo 'SchoolType --> '.$value->attributes()['SchoolType'];        
        echo "<br />";
        echo 'SchoolName --> '.$value->School->SchoolName;
        echo "<br />";
        echo 'SchoolLocation --> '.$value->SchoolLocation;
        echo "<br />";
        echo 'DegreeMajor --> '.$value->Degree->DegreeMajor[0];
        echo "<br />";
        echo 'EducationDetails --> '.$value->Degree->EducationDetails;
        echo "<br />";
        echo 'StartDate --> '.$value->Degree->DateofAttendance->StartDate[0];
        echo "<br />";
        echo 'EndDate --> '.$value->Degree->DateofAttendance->EndDate->AnyDate;
        echo "<br /><br />";
    
    }
    
    0 讨论(0)
提交回复
热议问题