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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀