dongyuan3094 2017-07-05 09:27
浏览 31
已采纳

想要在codeigniter中创建一个多维数组,如下面给出的数组

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] => 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
                            )

                    )

            )

    )

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条回答 默认 最新

  • dongmiao520892 2017-07-05 10:33
    关注

    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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)