php - PHP 警告:非法字符串偏移,错误
问题描述
在第 29 行出现错误,其中指出 $tree[$child['parent_id']]['children'][] = $child; 我正在使用 php5.5 错误日志显示:PHP 警告:第 29 行 /home/mysite.com/public_html/app/controllers/webController.php 中的非法字符串偏移 'parent_id'
public function getchild($parentID) {
$sql = "select id, parent_id from category where ";
if ( is_null($parentID) ) {
$sql .= "parent_id = 0";
}
else if ( is_array($parentID) ) {
$parentID = implode(',', $parentID);
$sql .= "parent_id in ({$parentID})";
}
else {
$sql .= "parent_id = {$parentID}";
}
$tree = array();
$idList = array();
if($this->db->count($sql)){
$res = $this->db->fetchAll($sql) ;
if(count($res)>0){
foreach($res as $row){
$tree[$row['id']] = $row;
$idList[] = $row['id'];
}
}
if (isset($idList) && is_array($idList)) {
$children = $this->getchild($idList);
foreach($children as $child) {
$tree[$child['parent_id']]['children'][] = $child;
}
}
return $tree;
}
else
{
$tree['id'] = $parentID;
return $tree;
}
}
请让我知道我做错了什么或如何解决错误。提前致谢
解决方案
推荐阅读
- vba - 在 VBA(Excel 宏)中授予注册表权限
- jquery - 使用 Jquery 更改键盘导航顺序
- python - 如何在急切执行中暂停和恢复渐变磁带?
- hibernate - 使用映射列表(键、值)作为带有 OR 条件的参数创建 JPQL(或标准)
- python - Python无法在鼠标重放程序中创建循环
- swift - Cocoa swift - 在 tableview 上缓慢加载数据
- amazon-web-services - AWS Lambda 在成功和超时之间交替
- amazon-cognito - AWS Cognito 不使用无服务器发送验证电子邮件
- javascript - ds3.js 颜色范围。
- javascript - POST 动态创建所需的输入字段