Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

annas

  • 2 years ago

3rd tutorial on php: contents: 1. if statement 2. if-else statement 3. if-elseif statement

  • This Question is Closed
  1. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    'if' statement is a decision making statement. Its syntax is: if(condition){ //block to be executed } In php how we use if statement lets have a look at it by a program. <?php $name = 'bob'; if($name=='bob'){ echo 'Hello bob'; } ?>

  2. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    output: Hello bob //because variable name == bob let see another example where the condition is false: <?php $name = 'bob'; if($name=='Mike'){ echo 'Hello bob'; } ?> in this case nothing will be displayed because the condition is fails.

  3. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    Now let move to words our next topic i.e. if-else statement It is same as if statement except it has an else block so that when the condition is false the control will be transfer to the else part. Let have an example: <?php $name = 'Mike'; if($name=='Mike'){ echo 'Hello Mike'; } else { echo 'Dear user you are not Mike'; } ?> output: Hello Mike because condition is true. Now, let see another example where condition is not true. <?php $name = 'bob'; if($name=='Mike'){ echo 'Hello Mike'; } else { echo 'Dear user you are not Mike'; //this line is executed this time } ?> output: Dear user you are not Mike

  4. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    Now lets move towards the next content i.e. if-elseif. In if-elseif multiple conditions and block are available. lets see an example: <?php $name = 'bob'; if($name=='Mike'){ echo 'Hello Mike'; } elseif($name=='bob') { echo 'Hello Bob'; } else { echo 'You are neither Bob nor Mike'; } ?> output: Hello Bob elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE.

  5. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    Well thats it for this tutorial. I hope this tutorial will be interesting and helpful for you guys. Good luck. :)

  6. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    for those who join the tutorial now can also see the previous tutorials. 1. http://openstudy.com/study#/updates/4ffa87a8e4b058f8b7666f25 2. http://openstudy.com/study#/updates/4ffb14c9e4b058f8b766d273

  7. malihe
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    fantastic

  8. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    thank you

  9. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 8

    @agdgdgdgwngo what do you think about the tutorials ???

  10. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.