Reputation: 81
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";
}
}
}
Upvotes: 0
Views: 175
Reputation: 41
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.
Upvotes: 1
Reputation: 799230
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.
Upvotes: 2