I'm new in PHP and I don't loop through all records using if/else statement in foreach loop.
$string = "a , b , 1, 2, 3, c, d, e";
$string = explode(' , ', $string);
foreach ($string as $value) {
if(is_int($value)){
echo 'Int ' . $value . '<br>';
}else{
echo 'Char ' . $value . '<br>';
}
}
I get this result from above code,
Output
Char a
Char b
Char 1, 2, 3, c, d, e
I expected following result, so kindly help me to figure out. Thanks
char a
char b
int 1
int 2
int 3
char c
char d
char e
Aucun commentaire:
Enregistrer un commentaire