我有一个字符串,我需要从中获取关联数组。我可以自由地将字符串修改为看起来像数组,但我仍然无法从中获取数组。我尝试过explode、json等。
$string = $row->id . ',' . $row->title . ',';
// 1,Home,3,Services,6,Service 1,7,Service 2,2,Products
例子
public function Menu($parent = null) {
$query = $this->menuManager->getPublicMenus()->where('parent', null)->order('sort_order');
if ($this->menuManager->getPublicMenus()->count() > 0) {
$menu = '';
foreach ($query as $row) {
$menu .= $row->id . ',' . $row->title . ',';
$menu .= $this->Menu($row->id);
}
return $menu;
}
}
我需要输出:
array
1 => "Home"
3 => "Services"
6 => "Service 1"
7 => "Service 2"
2 => "Products"
喵喔喔