0

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"; 
    } 
} 
} 
4

2 回答 2

2

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.

于 2012-04-12T03:42:40.313 回答
1

您可以使用serialize函数将数组转换为字符串。

检索到后,您可以使用unserialize函数将其转回数组。

于 2012-04-12T03:48:57.907 回答