多维方式迭代数组元素

时间:2015-03-25 13:34:58

标签: php arrays ajax

我对级联ajax选择实现的类别,变体和子变体进行了以下数组设置。

$config['categories']= array(

 'MEN'=>array(
        'Tanks',
        'Bags & Wallets'=>array('Backpacks','Briefcases','Messenger bags','Wallets'),
        'Belts & Buckles',
        'Bottoms'=>array('Pants','Shorts','Swim','Underwear'),
        'Coats & Jackets'=>array('Blazers','Coats','Jackets'),
        'Cufflinks',
        'Hats',
        'Shirts',
        'Shoes',
        'Suits',
        'Sweaters',
        'T-Shirts',
        'Ties', 
        'Clips & Bow Ties',
        'Other Clothing',
        'Other Accessories'

    ),
    'WOMEN'=>array(
        'Accessories'=>array('Belts','Eyewear','Gloves & Mittens','Hats           Legwear','Scarves','Watches','Shoe Accessories'),
        'Bags & Purses',

    )
);

我正在使用ajax构建级联类别下拉列表。

public function get_sub_categories_ajax() {

         $categories_selected = $this->input->post('category');  
         $load_all_catagories = $this->config->item('categories');


         $result = $load_all_catagories[strtoupper($categories_selected)];
         $subcategories = array();
          foreach($result as $key => $value) {

           $subcategories[$key] = $value;

         }

         if(!$this->input->is_ajax_request()) {

            exit('Not allowed');

         } else {

            $result =  array('#'=>'Please Select Variation')+$result;

            header('Content-Type: application/x-json; charset=utf-8'); 
            echo ( json_encode( array_values($subcategories)  )  );
         } 
    }

我遇到的问题是,当我选择" women" 时,我希望返回以下值 [配件,包和钱包] 当选择" bags" 时,我想列出。同样,当选择配件时,我想返回 [' Belts',' Eyewear''手套]

0 个答案:

没有答案