Hi I have a field from db with values 2,3,4,5,6,7
I want to make a if statment
if($str=='4'){
then do something
}
The question how can I make $str only one number '2' or '4'
How to split
Assuming you have the values as an array:
use a for loop or foreach, or each()
foreach ($my_array as $value) {
if ...
}
for ($i=0; $i <= count($my_array; $i++) {
if xyz do something...
}
while($x = each($my_array)) {
echo "$x[0] => $x[1]<BR>"; //to see them
if (x[1] == 4) {
do something...
}
}
I should have added if it's a string use explode. Using your same set of numbers:
$my_numbers = explode(",", $my_field);
Then you have an array to work with.
HTH
rinjani
those values are koming from session for example I registerd as session_register('access')
I have session_start()
in access are values 2,3,5,7,8
i need only number 2 or 3 without comma to make that if statment
if($access=='2'){
do something
}
Sorry rinjani I did not saw your post