Let's say you have an array, and want to run through it to check
<?php
$my_array = array('bus', 'car', 'bike', boat');
foreach ($my_array as $element) {
if ($element == 'bus') {
echo 'Pay the bus fare!';
} elseif ($element == 'boat') {
echo 'Hope you dont get seasick';
} else {
echo 'Cars and bikes are boring';
}
echo '<br>';
}
?>
Or
<?php
$my_array = array('bus', 'car', 'bike', boat');
foreach ($my_array as $element) {
switch($element) {
case 'bus':
echo 'Pay the bus fare!';
break;
case 'boat':
echo 'Hope you dont get seasick';
break;
default:
echo 'Cars and bikes are boring';
}
echo '<br>';
}
?>
Now, what interests me is "If I echo this result I get".
Are you really storing the data in an array, or in a string?
If it is a string, it will be impossible, since you cannot be 100% sure that the data is as expected.
If it is an array, then why bother making it a string?
It will already be an array of strings, and you can do the comparisons right away like what I gave in my example.