Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

php输出数组变成了对象

foreach ($rule as $key=>$value) {
     $data['role']['permissions'][$key] = [
         'roleId' => $info['title'],
         'permissionId' => $value['name'],
         'permissionName' => $value['title'],
         'actionList' => null,
         'dataAccess' => null
     ];
     foreach ($value['children'] as $k=>$v) {
         $data['role']['permissions'][$key]['actionEntitySet'][$k] = [
         'action' => $v['condition'],
         'describe' => $v['title'],
         'defaultCheck' => false
         ];
     }
}

为什么父遍历得到的$data['role']['permissions'][$key]是个对象,而子遍历得到的$data['role']['permissions'][$key]['actionEntitySet'][$k]却是数组?
父遍历我想得到的是数组该怎么写才对?
image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

看了一下,"actionEntitySet"有的输出对象有的输出数组,看你这段代码是没有问题,看下是否是其他的地方对结果做了一下处理


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...