There is such an array:

array(3) { [0]=> array(3) { ["variant_id"]=> int(154) } [1]=> array(3) { ["variant_id"]=> int(157) } } 

How to make an array start with one? Like this:

  array(3) { [1]=> array(3) { ["variant_id"]=> int(154) } [2]=> array(3) { ["variant_id"]=> int(157) } } 

If you have to use the cycle, it is desirable through foreach , I will be grateful for your answers.

  • one
    Are you sure you need it? I can assume that if you want to change the order in the array that starts from one, then something went wrong with you. Understand - any actions with the array below (whether it is filtering, sorting, etc.) do not give you guarantees of preserving the order (or the order of keys). You are not going to always change the sequence from zero to one in the array keys after all actions on the data? - zalex pm

1 answer 1

 $a = [0,1,2,3]; array_unshift($a, NULL); unset($a[0]); var_dump($a);