我想要像这样的数组格式
Array
(
[id] => 34
[restaurant_name] => Chow Pow
[state] => Odisha
[city] => Cuttack
[address] => Daraghabazar, Kumbhar Sahi
[logo] => c4ca4238a0b923820dcc509a6f75849b.jpg
[open_time] => 11:00
[close_time] => 22:00
[rating] => 3.5
[count_rating] => 4
[restaurant_email] => soumya@oricubetechnology.com
[service_type] => both
[status] => approved
[gst] => 5.6
[telephone_no] => 0674-23823456
[postcode] => 2000
[suburb] => SYDNEY
[abn] => 12345678901
[restaurant_id] => 1
[servicearea_postcode] => 753010
[servicearea_suburb] => 753010 - Cuttack
[delivery_time] => 00:45
[delivery_fee] => 100
[min_order] => 1000
[min_order_free] => 500
[cuisines] => Array
(
[0] => Array
(
[id] => 60
[restaurant_id] => 1
[dealsin] => Chinese
)
)
[coupons] => Array
(
[0] => Array
(
[id] => 1
[restaurant_id] => 1
[coupon_code] => PURBA100
[coupon_discount] => 20
[no_of_usage] => 5
)
)
[categories] => Array
(
[menus] => Array
(
[0] => Array
(
[id] => 11
[restaurant_id] => 1
[cat_name] => Baker's Treat - Breaddd
[itemname] => Elaichi Bread Roll
[food] => nonveg
[food_type] =>
[price] => 320.00
[restaurant_price] => 20.00
[stock_qty] => 20
[stock_out_qty] => 19
[commission] => 300.00
[item_img] => 6512bd43d9caa6e02c990b0a82652dca.jpg
[created_date] => 0000-00-00
)
[1] => Array
(
[id] => 15
[restaurant_id] => 1
[cat_name] => Baker's Treat - Breaddd
[itemname] => Bread Crumbsggggg
[food] => nonveg
[food_type] =>
[price] => 0.00
[restaurant_price] => 65.00
[stock_qty] => 0
[stock_out_qty] => 0
[commission] => 0.00
[item_img] => 9bf31c7ff062936a96d3c8bd1f8f2ff3.jpg
[created_date] => 0000-00-00
)
[2] => Array
(
[id] => 23
[restaurant_id] => 1
[cat_name] => Baker's Treat - Breaddd
[itemname] => Chiken Biriyani
[food] => egg
[food_type] =>
[price] => 0.00
[restaurant_price] => 300.00
[stock_qty] => 0
[stock_out_qty] => 0
[commission] => 0.00
[item_img] => 37693cfc748049e45d87b8c7d8b9aacd.jpg
[created_date] => 0000-00-00
)
[3] => Array
(
[id] => 24
[restaurant_id] => 1
[cat_name] => Baker's Treat - Breaddd
[itemname] => Chiken Biriyani1
[food] => veg
[food_type] =>
[price] => 0.00
[restaurant_price] => 89.00
[stock_qty] => 0
[stock_out_qty] => 0
[commission] => 0.00
[item_img] => 1ff1de774005f8da13f42943881c655f.jpg
[created_date] => 0000-00-00
)
[4] => Array
(
[id] => 32
[restaurant_id] => 1
[cat_name] => Baker's Treat - Breaddd
[itemname] => Vege Pie
[food] => veg
[food_type] =>
[price] => 45.00
[restaurant_price] => 45.00
[stock_qty] => 5
[stock_out_qty] => 5
[commission] => 0.00
[item_img] =>
[created_date] => 0000-00-00
)
[5] => Array
(
[id] => 34
[restaurant_id] => 1
[cat_name] => Baker's Treat - Breaddd
[itemname] => Finger bun
[food] => veg
[food_type] =>
[price] => 2.00
[restaurant_price] => 2.00
[stock_qty] => 1
[stock_out_qty] => 1
[commission] => 0.00
[item_img] =>
[created_date] => 0000-00-00
)
)
)
)
我已为此编写代码,但它仅显示最后一个类别菜单。我想如果我将连接类别循环中的数组,那么它将解决我的问题。但我无法做到这一点。以下是控制器代码
//To show the result of clicked restaurant from searched restaurant
public function restaurant_details($restaurant_id)
{
$search_suburb = $this->session->userdata('search_suburb');
$get_restaurant_details = $this->searchRestaurantModel->get_restaurant_details($restaurant_id, $search_suburb);
$restaurant_details = array();
foreach($get_restaurant_details as $res_details)
{
$get_cus = $this->searchRestaurantModel->get_restaurant_cuisines($res_details['restaurant_id']);
$get_cup = $this->searchRestaurantModel->get_restaurant_coupons($res_details['restaurant_id']);
$get_category = $this->searchRestaurantModel->get_restaurant_categories($res_details['restaurant_id']);
$restaurant_id = $res_details['restaurant_id'];
$res_details['cuisines'] = $get_cus;
$res_details['coupons'] = $get_cup;
$res_details['all_categories'] = $get_category;
//Category Items name
$restaurant_menus = array();
foreach($get_category as $res_category)
{
//echo $res_category['cat_name'];
$get_menu = $this->searchRestaurantModel->get_restaurant_menus($res_category['cat_name'], $res_details['restaurant_id']);
$res_details['categories']['menus'] = $get_menu;
//echo "<pre>";
//print_r($res_details);
//die();
}
array_push($restaurant_details, $res_details);
}
echo "<pre>";
print_r($restaurant_details);
die();
//Breadcrumb
$this->breadcrumbs->push('Home', '/');
$this->breadcrumbs->push('Search Results', 'restaurants/restaurant_search');
$this->breadcrumbs->push($res_details['restaurant_name'], '#');
$data['title'] = $res_details['restaurant_name']. 'Home Delivery in '.$res_details['servicearea_suburb'];
$data['restaurant_details'] = $restaurant_details;
$this->load->view('header', $data);
$this->load->view('restaurants_details');
$this->load->view('footer');
}
答案 0 :(得分:1)
替换代码
$res_details['categories']['menus'] = $get_menu; //---> you miss to add array
以下
$res_details['categories']['menus'][] = $get_menu; //---> now it will store value in array
希望这对你有用。如果还有什么让我们知道......