面对数组的奇怪情况..我正在使用 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
)
)
)