<?php
$jobsKeys = array('full.png','hr.png','mobile.png','java.png','python.png','net.png')
?>
<div class="row">
<ul class="list-group">
<?php foreach ($item as $job) : ?>
<?php
foreach($jobIcons as $jobsKeys){
if (stripos($job['title'], $jobsKeys['title']) !== false) {
echo "<li class='list-group-item'><img src=".$jobsKeys['image']." style='width: 25px;'> ". $job['title'] ." <span class='badge badge-primary badge-pill'>14</span></li>";
}else{
echo "false";
}
}
?>
<?php endforeach; ?>
</ul>
</div>
I'am trying to compare the title of the job with the icons from the array (stripos method). And condition when is true works for me the way I want, the problem is with the else statement.
foreach loop returns somthing like this:
false
false
false
false
false
<li>....</li>
false
false
false
<li>....</li>
I want to get somthinglike this: if you don't find match in jobIcons(in a whole array) then output false not in not in every itaration. Is it possible to write that in the else statement?
Sure. You can set a flag whenever you reach the else-statement and check the flag after the for-loop. Something like that:
This is not that elegant because you set the flag every time you encounter the else-statement but it is acceptable for your case I think.