【发布时间】:2014-12-04 04:10:04
【问题描述】:
面对数组的奇怪情况.. 我正在使用 LinkedIn API 来获取以两种格式返回数据的个人资料信息..
如果用户只有一项教育项目
educations=>education=>school-name
educations=>education=>date
...
如果有多个教育项目
educations=>education=>0=>school-name
educations=>education=>0=>date
...
educations=>education=>1=>school-name
educations=>education=>1=>date
...
现在我正在尝试使其保持一致并进行转换
educations=>education=>school-name
到
educations=>education=>0=>school-name
但是在我认为应该可以工作的代码中出现错误
if(empty($educations['education'][0]['school-name']))
{
$temp = array();
$temp['education'][0]=$educations['education'];
$educations = $temp;
}
“只有一个教育项目”失败,在第一行为 (isset,is_array 和 empty) 生成错误
PHP Fatal error: Cannot use string offset as an array in ...
print_r 返回
[educations] => Array
(
[education] => Array
(
[id] => 109142639
[school-name] => St. Fidelis College
[end-date] => Array
(
[year] => 2009
)
)
)
【问题讨论】:
-
你能
var_dump$educations的内容吗?