PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a little bit of problem here
$score1 = 80
This code doesn't work well as one of the splitdata[4] in a string but it still run the condition. How to i make the if condition to only execute if it is a number. Also, how do i declare $score1 as a number.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
tags, not [syntax=php]tags, when posting PHP code.
2) PHP is lazy typed. You don't need to set it as a number. However, you can try [b](int)$score1[/b] if you think it'll help.
3) You first sentence doesn't make sense to me.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Putting int() solved the problem. Initially, i thought the syntax should be int($score1). Thanks.
Let me clarify on the first sentence
$dfsplitdata[4] = it may contain string such as (abcde) or number only (after stripped off the %). Previous, before declaring $score1 as integer, (abcde) met the condition of "(trim($dfsplitdata[4], '%') >= $score1 )" which doesn't make sense because it would be "abcde >= 80". String > number. I might need some explanation on this coz i don't know what explanation on this, it might be the ASCII number count or etc. Anybody want to explain?
if you are always going to have that same pattern of ###% then you can just use php's str_replace function
mixed str_replace ( mixed $search, mixed $replace, mixed $subject [, int &$count] )