Insert value JSON with foreach?

I use codeigniter. I want insert this value JSON to database, but with following PHP code it insert just [ in table. how can fix this problem?
– i use mysql database and “var_dump($start_date,$percent);” output is as: ‘string(31) “[“2012\/08\/07”,“2011\/10\/29”]” array(1) { [0]=> string(2) “56” } [“2012\/08\/07”,“2011\/10\/29”]’

Html code:

<input name="start_date[]" value="2012/08/07">
<input name="start_date[]" value="2011/10/29">
<input name="percent[]" value="56">

This value JSON: [“2012\/08\/07”,“2011\/10\/29”]

PHP code:

    $start_date         = json_encode($this->input->post('start_date'));
    $percent       = $this->input->post('percent');

            print_r($start_date); // This output is as: ["2012\\/08\\/07","2011\\/10\\/29"]

            $data = array();
            foreach ($percent as $idx => $name) {
                $data[] = array(
                    'start_date' => $start_date[$idx],
                    'price_change' => $percent[$idx]
            $this->db->insert_batch('table', $data);

I do not see why you are turning an array of values into json?

show us the result of var_dump($_POST) (remove anything incriminating if you wish)

The reason you are only getting “[” is because you have $start_date as a string in json format but are trying to access it as an array, so for example $start_date[1] will access the 1st character in your json string.

Why dont you just leave $start_date as an array? Or do you want to insert both values in json format? Take the array syntax off $start_date in the foreach loop.