0

I want the array format like this

  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] => [email protected]
        [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
                            )

                    )

            )

    )

I have written the code for that but it will show only the last category menu only. I think if I will make concatenate the the array inside the category loop then it will resolve my issue. But I am unable to do that. Below is the controller code

//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');
    }

1 Answer 1

1

replace code

$res_details['categories']['menus'] = $get_menu; //---> you miss to add array

with following

$res_details['categories']['menus'][] = $get_menu; //---> now it will store value in array

Hope this will work for you. If is there anything else let us know...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.