0

I have an array like this based html code :

<div class="col-sm-12">

     <input type="checkbox" name="condition[]" checked="checked" value="1"> Dirty
     <input type="checkbox" name="condition[]" value="2"> Damage
     <input type="checkbox" name="condition[]" value="3"> Clean
     <input type="checkbox" name="condition[]" value="4"> Off Hire
</div>

This is the result on submit :

Array
(

[0] => Array
    (
        [0] => 1
    )

[1] => Array
    (
        [1] => 2
    )

[2] => Array
    (
        [2] => 3
    )

[3] => Array
    (
        [3] => 4
    )
 )

I want to change the all of key with defined name like this

Array
(

[0] => Array
    (
        [ID_INSPECTION] => 1
    )

[1] => Array
    (
        [ID_INSPECTION] => 2
    )

[2] => Array
    (
        [ID_INSPECTION] => 3
    )

[3] => Array
    (
        [ID_INSPECTION] => 4
    )
 )

So, I decide to looping and check them like this :

public function rubah_key_item_header($array){
    $detailNew = array();
    $i = 0;
    foreach ($array as $k => $v) {
        $detailNew[$k]['ID_CONDITION'] = $v[i];
        $i++;
    }
    return $detailNew;
}

$newArrayHeaderDetail = $this->rubah_key_item_header($arrayHeaderDetail);

I got this error :

 Severity: Notice

 Message: Use of undefined constant i - assumed 'i'
Fadly Dzil
  • 2,154
  • 3
  • 34
  • 85

1 Answers1

0

You missed $ before i.

Instead of

$detailNew[$k]['ID_CONDITION'] = $v[i];

it should be

$detailNew[$k]['ID_CONDITION'] = $v[$i];
AnkiiG
  • 3,468
  • 1
  • 17
  • 28