$_REQUEST = array(
'articolo' => array(
1 => 1,
3 => 'Sostituzione sostituzioni',
4 => 'Cambio olio'
),
'specifica' => array(
1 => 2,
3 => 'Camoin',
4 => 'Furgone'
),
'quantita' => array(
1 => 3,
3 => 5,
4 => 7
)
);
i need to insert on database like this
$_REQUEST['articolo'][1]
$_REQUEST['specifica'][1]
$_REQUEST['quantita'][1]
on database row and
$_REQUEST['articolo'][3]
$_REQUEST['specifica'][3]
$_REQUEST['quantita'][3]
on another row and ...
$_REQUEST['articolo'][4]
$_REQUEST['specifica'][4]
$_REQUEST['quantita'][4]
i just want to know how to make another array row by row
i need to print
1 -> $_REQUEST['articolo'][1]
2 -> $_REQUEST['specifica'][1]
3 -> $_REQUEST['quantita'][1]
Sostituzione sostituzioni -> $_REQUEST['articolo'][3]
Camoin -> $_REQUEST['specifica'][3]
5 -> $_REQUEST['quantita'][3]
Cambio olio -> $_REQUEST['articolo'][4]
Furgone -> $_REQUEST['specifica'][4]
7 -> $_REQUEST['quantita'][4]
thank
you need something like this:
foreach ($request as $key => $value)
{
$request[$key][1] //row1
$request[$key][3] //row2
$request[$key][4] //row3
}
Edit Based on the comments:
if the array is dynamic(you do not know the keys of the sub-array), you can do this instead:
foreach ($request as $key => $value)
{
foreach ($request[$key] as $key2 => $value2)
{
$request[$key][$key2] //here are your values
}
}
Now you have an idea on how to do it right? use those values inside that foreach
to add data to your database
$name = array_keys($_REQUEST);
$index = array_keys($_REQUEST['articolo']);
for($i=0; $i < count($index); $i++):
if($i + 1 % count($index)):
for($j=0; $j < count($name); $j++):
echo $name[$j].': '.$_REQUEST[$name[$j]][$index[$i]].'<br>'."
";
endfor;
echo '<hr>';
endif;
endfor;
output it's right now
articolo: 1 specifica: 2 quantita: 3
articolo: Sostituzione sotituzioni specifica: Camoin quantita: 5
articolo: Cambio olio specifica: Furgone quantita: 7
now just need to insert the ordinate data on database