I'm trying to implode an array to perform insertion , but i couldn't trigger the error i did. implode() [function.implode]: Invalid arguments passed *Please note my array size is not fix so i used foreach*
Array structure
[attcode] => Array ( [0] => [1] => [2] => )
[color] => Array ( [0] => [1] => [2] => )
[size] => Array ( [0] => [1] => [2] => )
[stock] => Array ( [0] => [1] => [2] => )
Working code
$attstring = array();//array for storing query set
foreach($productcount['attcode'] as $attcode){
$attstring[] = "'" . implode("','", $attcode)."'";
}
foreach($productcount['color'] as $attcolor){
$attstring[] = "'" . implode("','", $attcolor)."'";
}
foreach($productcount['size'] as $attsize){
$attstring[] = "'" . implode("','", $attsize)."'";
}
foreach($productcount['stock'] as $attstock){
$attstring[] = "'" . implode("','", $attstock) . "'";
}
$finalvalue = "(" . implode("), (", $attstring) . ")";
echo $finalvalue;
Desired output
('code','color','size',stock),
('code','color','size',stock),
('code','color','size',stock)