I have an array that contains another array like the following:
And I need to get the value of [extra]
, but the array can have more than one [#]
I also need to differentiate them, I have some breaking my head and can not find a viable option.
In my code I have a foreach
that contains the values of the complete array and I destine its options to $c[id], $c[cantidad], $c[base], $c[ingredientes], $c[salsa], $c[extra], $c[opciones]
but I have a for
that obtains the data but it does not work:
$ing = explode(",", $ingredientes);
//$ong = explode(",", $extras);
$cont=0;
for ($i = 0; $i < count($ing); $i++) {
if ($ing[$i] != "") {
$query = "SELECT * FROM c_ingredientes WHERE id = " . $ing[$i];
try {
$resp = $conn->obtDatos($query);
if ($conn->filasConsultadas > 0) {
foreach ($resp as $dts) {
$ingrediente = $dts['ingrediente'];
//$precio = $dts['precio'] * preg_split('/,/',$canti)[$i];
$precio = $dts['precio'] * $extras[$i];
//$precio = $dts['precio'] * $canti2[$i];
}
}
} catch (Exception $ex) {
echo $ex;
}
//$temp = preg_split('/,/',$canti)[$i];
//$temp = $ong[$i];
echo "<h6>($extras[i]) $ingrediente</h6>";
$ext.= " " . preg_split('/,/',$canti)[$i] . " " . $ingrediente . "<br>";
$importe += $precio;
}
}
The result of the previous code is this:
There will be more values that will enter the main array and I will have to take their respective extras, how do I make it work?