Sunday 3 February 2013

PHP Tutorial . Chapter 5 . PHP Control Statements (Part 1 if-else statement)

What fun is programming if you don't have control over the code ? Best coding practices include writing code that responds differently to different situations . Suppose you have a code let's say , which takes in the type of an employee in an office and accordingly outputs the salary for that position , lets say , what would you do ?

( Cookies again for C Programmers , this section is actually same as the if-else you were accustomed to before !! )

The most popular control statement in any programming language is the if-else construct . So how to use the if else construct ? Let's follow the following example and things will seem pretty easy then .

Algorithm :



Example

Lets say that we have a variable that stores the type of an employee at an office . We will check that variable and print out the corresponding salary .


$a = "General Manager";

if($a=="General Manager")
echo "1000000";
else if($a=="CEO")
echo "2000000";
else if($a=="Chairman")
echo "3000000";

?>

The above code outputs 1000000 .

Also an important aspect of php code is that it continues from the last block . Suppose you have a file containing both php and html . You have a block of php code , then you have some html and then again a block of php code , php will continue from the last line of the previous block . This will be clear from the following example .


Example


$a = 5 ;

if($a==5)
{
echo "The number is equal to 5
";
$a++;
echo "Now it's value is :- ".$a."
";
}
else if($a>5)
{
?>




echo "The number is greater than 5
";
echo "Also this statement is in the second php block
";
}
else
{

echo "The number is lesser than 5
";
echo "Also this statement is in the second php block
";
}

?>

This code won't show any error even though the else-if block is spread across the two blocks . This is quite a flexible feature !! It comes in handy if you want to place some html code within the conditions or within an incomplete block .

55 comments:

  1. your concept is right. i think this way too. thanks for explaining it well.

    Website Development company

    ReplyDelete
  2. Thanks for sharing these niche piece of coding to our knowledge. Here, I had a solution for my inconclusive problems & it’s really helps me a lot keep updates…
    Web design courses in Chennai

    ReplyDelete
  3. the discussion about the control statement everything was crystal clear keep sharing.
    Web design training in Chennai

    ReplyDelete
  4. HTML5 Courses in Chennai Training

    Hi, Thanks for sharing this valuable blog.I was really impressed by reading this blog. I did HTML5 Training in Chennai at reputed HTML5 Training Institutes in Chennai. This is really useful for me to make a bright future in designing field.

    HTML Training in Chennai

    ReplyDelete
  5. This is a wonderful informative blog here i had chance to get useful information keep posting...
    JAVA Training in Chennai|JAVA Training Institutes in Chennai

    ReplyDelete
  6. Android Training in Velachery

    Your blog is really useful for me. Thanks for sharing this useful blog..Suppose if anyone interested to learn Android Course in Chennai please visit fita academy which offers best Android Training in Chennai at reasonable cost.

    Android Training Institutes in Chennai

    ReplyDelete
  7. This post having niche information to make myself updated. Angularjs is the extended version of HTML with new attributes. It’s a JavaScript framework that can be added to an html page with a tag of script.if you want to study
    Angular training in chennai get into FITA.
    Angular course in chennai

    ReplyDelete
  8. Digital Marketing Training in Chennai

    Thanks for sharing this informative blog. Recently I did Digital Marketing courses in Chennai at a leading digital marketing company. It's really useful for me to make a bright career. If anyone wants to get Digital Marketing Training in Chennai visit infiniX.

    Regards...

    Digital Marketing Course in Chennai

    ReplyDelete
  9. Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post.very nice blogs!!!PHP Training in chennai | PHP Training chennai | PHP course in chennai | PHP course chennai


    ReplyDelete

  10. if i share this blog weblogic Server Training in Chennai aims to teach professionals and beginners to have perfect solution of their learning needs in server technologies.Weblogic server training In Chennai

    ReplyDelete
  11. Nice blog...Very useful information is providing by ur blog..here is a way to findGreens Technologies Training In Chennai

    ReplyDelete
  12. Excellent post, I agree with you 100%! I’m always scouring the oracle for new information and learning whatever I can, and in doing so I sometimes leave comments on blogs.Oracle Training In Chennai

    ReplyDelete
  13. Excellent post, I agree with you 100%! I’m always scouring the oracle for new information and learning whatever I can, and in doing so I sometimes leave comments on blogs.Oracle Training In Chennai

    ReplyDelete
  14. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Oracle PL/SQL Training In Chennai

    ReplyDelete
  15. I read your blog it's really good, thanks for sharing valuable information with us.
    Excellent Article, Nice to read your article, very informative.
    Excellent article Top AC mechanics Professional Camera sellers ChennaiCatering Service in ChennaiTop Educational Institute Chennai

    Excellent Article
    swimmingpool contractor chennai
    swimmingpool equipment dealer chennai
    swimmingpool consultant chennai

    ReplyDelete
  16. I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future reference.

    selenium Training in Chennai
    Selenium Training Chennai
    iOS Training in Chennai
    iOS Training Institutes in Chennai
    JAVA J2EE Training Institutes in Chennai
    Java course

    Selenium training in chennai
    Selenium training institute in Chennai
    ios developer course in chennai
    ios classes in chennai
    JAVA Training Chennai
    JAVA J2EE Training in Chennai

    ReplyDelete
  17. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    Air Hostess Training in Chennai | Air Hostess Training Institute in Chennai | Air Hostess Academy in Chennai | Air Hostess Course in Chennai | Air Hostess Institute in Chennai

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    CCNA Training in Chennai
    DevOps Training in Chennai
    DevOps Training institute
    DevOps Training near me
    Best CCNA Training Institute in Chennai
    CCNA certification in Chennai

    ReplyDelete
  20. your blog informations are really creative and It contains full of new innovative ideas.
    thank you for sharing with us.please update more data.
    AWS Training Institutes in T nagar
    Best AWS Training Institute in Anna nagar
    AWS Training in Bangalore
    AWS Training

    ReplyDelete
  21. Very Clear Explanation. Thank you to share this
    Regards,
    PHP Training in Chennai | PHP Course in Chennai

    ReplyDelete


  22. Flex board is a material that is designed specifically to accept the flex material bonding. Flex board printing Flex Printing Company in Rohini is the safest and most durable way to apply your printed flex material to a banner or a sign rather than to clothing or other similar mediums. https://www.abhiprint.com/flex-printing-in-delhi.php We are a prominent manufacturer, supplier and service provider of flex printing services in delhi that is highly effective and efficient. We do a detailed research and make use of the mot cost effective technologies to suit the exact requirements of our prestigious customers. Moreover, we have devised a better pricing policy that makes flex printing available at market leading prices, ensuring complete customer satisfaction.

    ReplyDelete
  23. Infycle Technologies, the No.1 software training institute in Chennai offers the leading Python course in Chennai for tech professionals and students at the best offers. In addition to the Python course, other in-demand courses such as Data Science, Selenium, Oracle, Java, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete