[keyboard] => Array ( [0] => Array ( [0] => Array ( [text] => Роллы ) [1] => Array ( [text] => Соки Напитки ) ) [1] => Array ( [2] => Array ( [text] => Дополнительно ) [3] => Array ( [text] => Сеты ) ) [2] => Array ( [4] => Array ( [text] => Десерты ) [5] => Array ( [text] => Салаты ) ) 

There is an array, how can I start a key with 0 inside each array?

    2 answers 2

    If you're talking about nested arrays, you can renumber something like this:

     foreach($data['keyboard'] as &$d){ $d = array_values($d); } 

    or

     $result['keyboard'] = array_map('array_values', $data['keyboard']); 

      For example, like this:

       <? $a = array (0 => 'Text 0', 1 => 'Text 1'); print_r($a); ?> 

      Or like this:

       <? $a = array ('Text 0', 'Text 1'); print_r($a); ?> 

      Added in response to a comment under the answer ... http://php.net/manual/ru/function.array-chunk.php

      preserve_keys If set to TRUE, the keys of the original array will be preserved. The default is FALSE, which re-indexes each part with numeric keys.

      • I do not need to manually - Ruslan Free
      • Do you have an example of how this array is created? - Vladimir Klykov
      • $ test = array_chunk ($ tes, 2, true); - Ruslan Free
      • So take a look at the dock on the function that you use =) - Vladimir Klykov
      • What is a minus, for comments came to the correct answer - teran