foreach循环并获取codeigniter中的循环值,php

时间:2016-01-18 04:37:25

标签: javascript php jquery arrays codeigniter

我有一个foreach循环,循环获取filename,alt和caption的值。

控制器

public function save_product(){
        log_message('debug', '['.__CLASS__.']['.__FUNCTION__.'][start]');
        $this->load->helper('form');

            //Grab all elements of the form with a name attribute
            $post = $this->input->post(NULL, TRUE);

            //$key refer to the $this->input->post('item_id');
            //$value refer to the value of the post key

            foreach($post as $key=> $value)
            {
                //retrieve the $key that start with 'images_files'
                if (0 === strpos($key, 'images_files'))
                {
                    log_message('debug', '['.__CLASS__.']['.__FUNCTION__.']['.$key.']['.print_r($value,TRUE).']');
                    var_dump($value);
                    echo "</br>";
                }
                elseif(0 === strpos($key, 'images_alt'))
                {
                    log_message('debug', '['.__CLASS__.']['.__FUNCTION__.']['.$key.']['.print_r($value,TRUE).']');
                    var_dump($value);
                    echo "</br>";
                }
                elseif(0 === strpos($key, 'images_caption'))
                {
                    log_message('debug', '['.__CLASS__.']['.__FUNCTION__.']['.$key.']['.print_r($value,TRUE).']');
                    var_dump($value);
                    echo "</br>";
                    /*array_push($images, 
                        array(
                            ,,$value)
                    );*/
                }
            }
            //var_dump($images);

            $item_id = $this->input->post('item_id');
            $category_id = $this->input->post('category_id');
            $item_info = $this->input->post('information');
            $oldcolor_id = $this->input->post('oldcolor_id');
            $color_id = $this->input->post('color_id');
            if ($color_id == "")
            {
                $color_id = $oldcolor_id;
            }
            else
            {
                $color_id = $color_id;
            }
            $isClearance = $this->input->post('isClearance');
            $parent_item_id = $this->input->post('parent_item_id');
            $model_no = $this->input->post('model_no');
            $volume = $this->input->post('volume');
            $short_desc = $this->input->post('short');
            $long_desc = $this->input->post('long');
            $release_from = $this->input->post('from');
            $release_to = $this->input->post('to');

            $this->load->model('backend_product_model');
            $this->backend_product_model->product_update($item_id, $category_id, $item_info, $color_id, $isClearance, $parent_item_id, $model_no, $volume, $short_desc, $long_desc, $release_from, $release_to);
    }

输出

array(1) { ["4548736020191"]=> array(1) { ["filename"]=> string(36) "875fb89e3d00a78e177a0ad4ab0c2fde.jpg" } } 
array(1) { ["4548736020191"]=> array(1) { ["alt"]=> string(5) "alt 1" } } 
array(1) { ["4548736020191"]=> array(1) { ["caption"]=> string(9) "caption 1" } } 

如何才能获得“875fb89e3d00a78e177a0ad4ab0c2fde.jpg”,“alt 1”和“caption 1”以便将其他“post”信息与product_update()函数一起传递?

0 个答案:

没有答案