dimanche 25 octobre 2015

PHP Adding an element to the beginning of an array without changing other array numeric keys

Since version PHP > 5.4 , the '+' is no longer can be use to combine 2 numeric key array. any alternative to combine 2 numeric key array without change the key? for example

myarray1 =  [0 => '-'];
myarray2 = [8 => string 'CUACA BURUK' ,
            3 => string 'JALAN SESAK' ,
            2 => string 'KEMALANGAN' ,
            7 => string 'KENDERAAN ROSAK' ,
            6 => string 'KURSUS/BENGKEL/SEMINAR' ,
            9 => string 'LAIN-LAIN' ,
            4 => string 'LAWATAN TAPAK/KERJA LUAR' ,
            5 => string 'MESYUARAT',
            ];

I want to create a combo box, the second array is an array that I get from my database and want to and additional blank option to user. I want retain the key and the element when merge the 2 array. If I using the array_merge, it will change the key.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire