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"; 
    } 
} 
} 
2
  • Consider more normalization. If the data is ever queried or is part of business rules it is usually the appropriate route. Otherwise, the keyword is "serialize".
    – user166390
    Commented Apr 12, 2012 at 3:51
  • if you guys help me with the code i will appreciate...xx Commented Apr 12, 2012 at 3:52

2 Answers 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.

1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.