egturnkey Posted March 13, 2010 Share Posted March 13, 2010 Hello friends, If i have $manal = "40"; and i wanna create random number btween 1 to 100 $random = rand(1, 100); * not sure it is right or wrong for random function then if we have text_1 / text_2 i wanna say if $random >= $manal then show text_1 if else ( i mean $random < $manal ) then show text_2 i how write it in php so can anyone fix it to me and write it Link to comment https://forums.phpfreaks.com/topic/195132-how-to-say-it-in-php-if-and-else/ Share on other sites More sharing options...
egturnkey Posted March 13, 2010 Author Share Posted March 13, 2010 i've tried this but gives error <?php $manal = "40"; $random = rand(1, 100); $text_1 ="text 1"; $text_2 ="text 2"; if $random >= $manal { echo "$text_1"; } else { echo "$text_2"; } ?> Link to comment https://forums.phpfreaks.com/topic/195132-how-to-say-it-in-php-if-and-else/#findComment-1025696 Share on other sites More sharing options...
teamatomic Posted March 13, 2010 Share Posted March 13, 2010 You need round brackets to contain the conditional statement: if ($random >= $manal) HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/195132-how-to-say-it-in-php-if-and-else/#findComment-1025719 Share on other sites More sharing options...
Instigate Posted March 13, 2010 Share Posted March 13, 2010 I wrote this. Just a small modification. <?php $manal = "40"; $random = rand(1, 100); $text_one = "Text One"; $text_two = "Text Two"; echo $random; echo "\n"; if ($random>= $manal) { echo $text_one; } else { echo $text_two; } ?> Link to comment https://forums.phpfreaks.com/topic/195132-how-to-say-it-in-php-if-and-else/#findComment-1025720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.