i'm creating an PHP Function and i get one problem...
I can't set the foreach value into a variable inside the function.
My code is this...
The array:
$baremos_precios = array(
/* [baremo (id)] => [kilos_precio] => [kilos_hasta($key) => precio($value)] */
1 => array('kilos_precio' => array(
/* kilos hasta => precio (sin IVA) */
5 => 6.6,
10 => 7.76,
20 => 11.03,
30 => 14.79,
40 => 17.13,
50 => 19.46,
60 => 21.79,
70 => 24.12,
80 => 26.46,
90 => 28.8,
100 => 31.14,
120 => 35.8,
140 => 40.47,
160 => 45.14,
180 => 49.83,
200 => 54.2,
225 => 56.4,
250 => 58.59,
275 => 63.77,
300 => 68.94,
325 => 74.1,
350 => 79.28,
375 => 84.45,
400 => 89.62,
425 => 94.79,
450 => 99.96,
475 => 105.12,
500 => 108.08,
550 => 110.07,
600 => 113.08,
650 => 117.02,
700 => 125.53,
750 => 134.03,
800 => 142.52,
850 => 151.02,
900 => 159.53,
950 => 168.02,
1000 => 176.53,
1001 => 0.16 // precio por cada kilo apartir de >1000, ex: 1100kg => 0.16 * 1100 = 176€ + IVA
)
)
);
And the function with foreach's
function obtener_precio($baremo, $kg){
$precio = 0;
foreach($baremos_precios AS $key => $value){
if($key == $baremo) {
foreach ($value['kilos_precio'] as $secondkey => $secondvalue) {
$kilos_array = [$secondkey];
if($kilos_array[0] == $kg){
$precio = $secondvalue;
}
}
}
}
return $precio;
}
Okay, now i'm trying this one...
echo obtener_precio(1, 200);
And from it' i want to get result ===> 54.2, but i always got 0
Where is the problem?, Thanks!