Php 如何从该数组中获取值
我如何获取学校类型、学校位置、学位名称、开始日期和结束日期 我试着像这样接受这些值Php 如何从该数组中获取值,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我如何获取学校类型、学校位置、学位名称、开始日期和结束日期 我试着像这样接受这些值 foreach ($Edu as $attr) { $attr->SchoolType; } 但它显示的是空值 这是我的数组 Array ( [@attributes] => Array ( [SchoolType] => University ) [School] => Array ( [SchoolName] => Northe
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
)
)
请帮助我获取此单个数组中的值。您需要使用索引。试试
$attr[0][SchoolType]代码>
对整个数组继续使用计数器变量
循环看起来像这样
$i = 0;
foreach ($Edu as $attr)
{
$attr[$i][SchoolType]; // whatever your code has to happen.
$i++;
}
如果$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) { }
请问,我如何在foreach循环中做到这一点?plsIf Edu包含问题中的数据,因为foreach将为您提供[@attributes]、[School]、[School location]的内容。但如果该数据是foreach中$attr的var_dump,只需将Edu更改为attr,例如$attr['@attributes']['SchoolType']
谢谢,但我只得到'N':(嗨,事实上这是我的完整数组,我尝试foreach循环,因为它有许多像我们一样的数组..有一个问题,我无法获得正确的细节,因此通过var_export($arra)生成输出);然后放在那里嗨,谢谢,我完全明白了。你能告诉我如何在一个循环中做到这一点吗pls@StackRaja我已经更新了答案。如果它有效,请接受它。:)您好,谢谢,…但是,它只给我结果o
对每个数组执行此操作。对于嵌套数组,请使用sizeof(array)启动for循环作为计数器限制器。sizeof方法将为您提供限制器值。