0
I’m trying to make a if
within a foreach
and the situation is as follows:
I have a array
who I called $plates who returns like this:
array(2) { [0]=> array(1) { ["chave"]=> string(1) "1" } [1]=> array(1) { ["chave"]=> string(1) "3" } }
And I tried this code:
foreach($matriculas as $matricula){
if(in_array($row['id_curso'],$matricula)){
echo '<a href="" class="btn btn-success disabled">Matriculado</a>';
}else{
echo 'nois';
}
}
I would like to show the information if the value of $row['id_curso']
exist in $matricula
, if it does not exist it should show any button. The problem is that it displays both, ie existing $row['id_curso']
in $matriculas
or not existing. There is a way to correct this?
You don’t need to iterate the
array $matriculas
with theforeach
the functionin_array
already checks whether or not there is!– Igor Mello
@Igormello if I don’t use foreach it won’t find because the array is Multi Dimensional... If it were a simple array it would run!
– HananiaMizrahi
my mistake, had not noticed this. I made a possible solution take a look!
– Igor Mello