I would use the numbers as keys for an index:
$data = '1;3;5;7;9';
$index = array_flip(explode(';', $data));
Now you can simply use isset
or array_key_exists
to check if that number is in $data
:
for ($i=0, $n=count($someArray); $i<$n; ++$i) {
if (array_key_exists($index, $i)) {
// $i is in $data
}
}
You can even do the reverse, iterate the numbers in $data
and see if they are in the range from 0 to count($someArray)
-1:
$data = '1;3;5;7;9';
$n = count($someArray);
foreach (explode(';', $data) as $number) {
if (0 <= $number && $number < $n) {
// $number is in range from 0 to $n-1
}
}