ciao a tutti
ho un array chiave/valore. ogni 4 chiavi/valori compongono un gruppo specifico (user, val1, val2, val3);
i valori di questo array li devo inserire in una tabella db;
ogni gruppo è una row della tabella.
avvio un altro foreach() per la query, tante query quanti sono i gruppi;
script:
Codice PHP:
foreach($arr as $key =>$valore)
{
if($key % 4 == 0){$user[] = $valore; }else {$vimeex[] = $valore;}
}
foreach($vimeex as $key => $value)
{
if($key % 3==0){$vi[]=$value;}else{ $meex[]=$value;}
}
foreach($meex as $key => $value)
{
if($key % 2==0){$me[]=$value;}else{ $ex[]=$value;}
}
foreach($user as $key => $value)
{
try{
$sql="insert...."
$s->bindValue(':us', $value );
$s->bindValue(':vi', $vi[$key] );
$s->bindValue(':me', $me[$key] );
$s->bindValue(':ex', $ex[$key] );
....
}catch(PDException $e)
{
echo $e->getMessage();
}
}
però vorrei capire se ci possono essere altre soluzioni....