mysql - PHP store array to database logical issue -


i have array follows:

$data = array('john',22,'peter',31,'kevin',30,'jessy',28.......'revin',23); 

this array contains thousands of elements in same format name, age.

now need insert array in table follows using php/mysql function.

-------------------- id     name    age  -------------------- 1      john     22  2      peter    31 3      kevin    30 

please note don't give options loops or explode. appreciated

i hope bellow code work based on requirement, happy coding :-)

        $data=array('john',22,'peter',31,'kevin',30,'jessy',28);// list of array         $array=array_chunk($data, 2);// converting array  multidimensional array         $arraytostr = implode(',', array_map(function($el){ return "('".$el['0']."',".$el['1'].")"; }, $array)); // implode multidimensional array ','separate array         $query="insert test (fname,age) values ".$arraytostr;// append new ',' separate array query 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -