1
I have the array
down that is giving a problem.
When I give a search it only seeks some values it is not finding the 2018-06-11, 2018-06-18 and the 2018-06-26
The rest works perfectly
$hoje = "2018-06-11";
$diario = array(
"0.25" => "2018-06-11",
"0.35" => "2018-06-12",
"0.38" => "2018-06-13",
"0.50" => "2018-06-14",
"0.00" => "2018-06-15",
"0.25" => "2018-06-18",
"0.37" => "2018-06-19",
"0.25" => "2018-06-20",
"0.23" => "2018-06-21",
"0.45" => "2018-06-22",
"0.33" => "2018-06-25",
"0.28" => "2018-06-26",
"0.40" => "2018-06-27",
"0.31" => "2018-06-28",
"0.28" => "2018-06-29",
"0.32" => "2018-07-03"
);
echo $lucrohoje = array_search($hoje, $diario);
The array has equal keys so the last one is the one that prevails. You can see that the array will have less element use the
var_dump()
or theprint_r()
to confer.– rray
Is that the problem, should it be the other way around maybe? Date as key.
– Leite
As long as the key doesn’t repeat itself, it’s okay, I don’t know if that’s the case.
– rray
OK really was the problem, thank you very much
– Lucas Moraes
It seems to be yes. And it is no longer necessary to use the
array_search
. Suffice<?php echo $diario[$hoje] ?>
(Confirming that the key exists clear)– Leite