【发布时间】:2016-05-21 15:38:23
【问题描述】:
我正在尝试修复我刚接触的程序中的一些错误:
if (strtoupper($xmlnode["tag"])=="RANDOM"){
$liarray=array();
$children = $xmlnode["children"];
for ($randomc=0;$randomc<sizeof($children);$randomc++){
if (strtoupper($children[$randomc]["tag"]) == "LI"){
$liarray[]=$randomc;
}
}
在strtoupper($children[$randomc]["tag"]) 我收到错误:
Warning: Illegal string offset 'tag'
为什么会发生这种情况,我该如何纠正?如果需要,我可以添加更多代码。
【问题讨论】:
-
$xmlnode没有元素“标签”。做var_dump($xmlnode)看看里面有什么 -
$xmlnode不是数组,而是字符串。您可能想研究使用函数将其拆分为数组。