php - Add missing keys into array -


I have an array like this, which has missing keys:

  array 2) {[0] = & gt; String (4) "Bill" [2] = & gt; String (13) "billy@kid.com"}   

How can I add missing keys as values ​​in the form of empty strings? I want this as a result:

  array (3) {[0] => String (4) "Bill" [1] = & gt; String (0) "" [2] = & gt; String (13) "billy@kid.com"}    

Your questions are very vague And, in fact, the difficulty of understanding what you want, from my interpretation, it seems that you want to insert a key in the array in the existing keys with the index line.

You can try something like this: A clean array (& $ array) {end ($ array); $ Max = key ($ array); // Get the last key as maximum! ($ I = 0; $ i & lt; $ max; $ i ++) {if (! Isset (array $ [i]) $ {$ array [$ i] = ''; }}} Clean ($ array);

Comments