I have a list of cities, these cities may exists once or repeated several times, or may not exists at all.
With php I want to check if city is in the foreach, and if exists print only one input out.
Below works perfect, print city only if exist, but repeats the existing:
**Updated (added afterwards):**
$paradasarray= array();
$xml = new SimpleXMLElement($viajes);
foreach ($xml->parada as $excursion) {
$paradasObject = new stdClass();
$paradasObject->localidad = $excursion->localidad;
$paradasObject->localidad = str_replace('/<![CDATA[(.*)]]>/', '',
$paradasObject->localidad); $paradasarray[] = $paradasObject;
}
$paradasarray = json_encode($paradasarray); $paradasarray =
json_decode($paradasarray);
**end updated**
foreach ($paradasarray as $parada) {
if (strpos($parada->localidad, 'Benalmádena') !== false) {
echo '<option value="Benalmádena Costa">Benalmádena Costa</option>';
}
if (strpos($parada->localidad, 'Estepona') !== false) {
echo '<option value="Estepona">Estepona</option>';
}
}
I have tried with break, however or I only get one of the two cities when I should get both, or none of them.