Hello I would like to store string which comes from json encode to get it store in MySQL, but the thing is that the array returned nothing. Here is my code:
$com = array("1-1","1-2","1-3");
$classcom=array();
for ($i=1; $i<(int)$totaleleve; $i++) {
$eleve=array();
foreach($com as $value)
{
array_push($eleve,'2');
}
$final="'".json_encode($eleve)."'";
array_push($classcom,$final);
echo $final;
echo $classcom;
}
echo $classcom;
For your information, $totaleleve='20', and I do $final="'".json_encode($eleve)."'"; so that I can concentrate strings of the array to be able to insert it into the SQL statement, which looks something like this:
$sql="INSERT INTO table VALUES (".explode(",", $classcom).")"
// so that it looks like something like this:
$sql="INSERT INTO table VALUES ('["2","2","2"]','["2","2","2"]','["2","2","2"]')
the $final gave me '["2","2","2"]' which i wanted, but when i do array_push($classcom,$final);, it just gave me a blank array :
Array
Can someone help me, please? Thank you!