Jump to content

I hate if and if else . how to write it


egturnkey

Recommended Posts

Hello friends,

 

If we have the following

 

$case1 = "11111";
$case2 = "2222";
$ad_one = "love";
$ad_two = "hate";
$ratio = "40";

srand ((float) microtime() * 10000000);
$random = rand(1, 100);

 

 

i wanna say the following manic problems

 

if ($ad_two == $case1 || $ad_two == $case2) {
echo $ad_one;
} else {

if ($random>= $ratio) {
echo $ad_one;
}
else {
echo $ad_two;
}

 

but it shows error (syntax error, unexpected $end)

 

i know there is something wrong in if,else . can anyone please re-write it !  :'(

 

Link to comment
Share on other sites

Proper indenting will help you with these problems.

 

Here is your code, poorly indented:

<?php
if ($ad_two == $case1 || $ad_two == $case2) {
echo $ad_one;
} else {

if ($random>= $ratio) {
echo $ad_one;
}
else {
echo $ad_two;
}
?>

 

Here is your code, indented in some manner:

<?php
if ($ad_two == $case1 || $ad_two == $case2) {
    echo $ad_one;
} else {
    if ($random>= $ratio) {
        echo $ad_one;
    } else {
        echo $ad_two;
    }
// <- With proper indenting, we see clearly that you're missing a closing bracket
?>

 

Fixed.

<?php
if ($ad_two == $case1 || $ad_two == $case2) {
    echo $ad_one;
} else {
    if ($random>= $ratio) {
        echo $ad_one;
    } else {
        echo $ad_two;
    }
}
?>

 

You should invest in an IDE that highlights matching brackets.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.