简体   繁体   中英

how to update table from array multidimension with php

how can i update data from array multidimension in php, but its from key and value array like this :

$array1=array(
    array('data1'=>'name','data2'=>'age'),
    array('data1'=>'names','data2'=>'ages')
);

how can i get result from array like this

UPDATE tablename SET data1='name',data2='age' WHERE 1;

i tried this but the result not like above

foreach($array1 as $arrays) {
    foreach($arrays as $key => $value){
        echo $key."="."'".$value."'".", ";
    }
}

result:

data1='name',data2='age', data1='name',data2='age'

i want result like this :

data1='name',data2='age'

i hope can help me.

Because you only want to get content of first array, you should loop through first array only

foreach($array1[0] as $key => $value){
    echo $key."="."'".$value."'".", ";
}
// data1='name', data2='age', 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM