简体   繁体   中英

how to save the array data into mysql database

stated array getting set of combinations....please help me and let me know how to save list of record into mysql database.....database contains three fields (set1 set2 set3)...

regards,

$array1 = array('rough', 'smooth', 'coarse'); 
$array2 = array('shiny', 'matte', 'rough'); 
$array3 = array('very large', 'large', 'medium', 'small'); 

$array=array_merge($array1,$array2,$array3); 

$combinations=array(); 
for($x=0;$x<(count($array)-2);$x++) { 
$a=$array[$x]; 
for ($y=$x+1;$y<count($array);$y++) { 
    $b=$array[$y]; 
    for ($z=$y+1;$z<count($array);$z++) { 
        $c=$array[$z]; 
        $combinations[]="$a, $b, $c"; 
    } 
} 
} 

The easiest way is to just use json_encode() to turn the array into JSON before storing. This way the data can be available to other processes and languages with minimal hassle.

You can use the serialize function to turn the array into a string.

Once retrieved, you can then use the unserialize function to turn it back into an array.

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