我如何从该数组中获取值

时间:2015-05-16 13:06:05

标签: php arrays multidimensional-array

我如何参加SchoolType,SchoolLocation,DegreeName,StartDate和EndDate?

我试图像这样采取这些价值

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

但它向我显示空值。

这是我的数组

    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
    )
    )

请帮我把这个数组中的值。

2 个答案:

答案 0 :(得分:0)

您需要使用索引。试试$attr[0][SchoolType]; 继续使用完整数组的计数器变量。

循环看起来像这样;

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

答案 1 :(得分:0)

如果$ Edu是包含您编写的数据的数组,则为代码

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]);

给出结果

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