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 .

45 comments:

  1. NICE BLOG!!! Thanks for sharing useful information about FNT Softwre Solutions and being one of best Software Training institute in Bangalore we agree that this blog is very useful for the students are Searching for best software courses, I would really like to come back again right here for like wise good articles or blog posts. Thanks for sharing...PHP Training Bangalore .

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

    Website Development company

    ReplyDelete
  3. Nice blog...Very useful information is providing by ur blog..here is a way to find

    weblogic training in bangalore

    ReplyDelete
  4. Nice blog...Very useful information is providing by ur blog..here is a way to find

    Php training institute in bangalore

    ReplyDelete
  5. Hi, Its really very informative and useful blog..Thanks for sharing this useful information about PHP Course.

    PHP Training

    ReplyDelete
  6. Thanks for updating new information about web designing. Practically, you have shared lot of details about website designing. Also share your new updated details about website creation. Thanks mate.
    Web Designing training in Chennai

    ReplyDelete
  7. 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
  8. the discussion about the control statement everything was crystal clear keep sharing.
    Web design training in Chennai

    ReplyDelete
  9. 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
  10. PHP Training Chennai

    I get a lot of great information from this blog. Thank you for your sharing this informative blog. Recently I did PHP course at a leading academy. If you are looking for best PHP Training Institute in Chennai visit FITA IT training academy which offer real timePHP Training in Chennai.

    PHP Course in Chennai

    ReplyDelete
  11. Are you looking for Best DOT NET Training in Chennai? Let us know we are ready to serve for your career. FITA is pleased to inform you that; we provides practical training on all the technologies with the MNC exports having more than 5 years of experience in your preferred domain. Get your career with our knowledge.
    DOT NET Training Institutes in Chennai|DOT NET Training Chennai

    ReplyDelete
  12. 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
  13. 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
  14. Dot Net Training Chennai

    Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.If anyone wants to get Dot Net Training in Chennai reach FITA, rated as No.1 Dot Net Training Institute in Chennai.

    Dot Net Course in Chennai


    ReplyDelete
  15. 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
  16. 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
  17. Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for Learners..
    Mysql Training in chennai | Mysql Training chennai | Mysql course in chennai | Mysql course chennai

    ReplyDelete
  18. 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
  19. Thanks for sharing informative article on wordpress. Being a most advanced CMS tool, wordpress help you to create sophisticated website with ease. Wordpress Training in Chennai

    ReplyDelete

  20. 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
  21. Nice blog...Very useful information is providing by ur blog..here is a way to findGreens Technologies Training In Chennai

    ReplyDelete
  22. i wondered keep share this sites .if anyone wants realtime training Greens technolog chennai in Adyar visit this blog..performance tuning training In Chennai and more Oracle Training In Chennai

    ReplyDelete
  23. once again sharing this informative blog .Datastage training In Chennai It uses a graphical notation to construct data integration solutions and is available in various versions may visit greens technology chennai in adyar Greens Technologys Training In Chennai

    ReplyDelete
  24. i gain the knowledge of Java programs easy to add functionalities play online games, chating with others and industry oriented coaching available from greens technology chennai in Adyar may visit.Core java training In Chennai

    ReplyDelete
  25. fantastic presentation .We are charging very competitive in the market which helps to bring more oracle professionals into this market. may update this blog . Oracle training In Chennai which No1:Greens Technologies In Chennai

    ReplyDelete
  26. 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
  27. 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
  28. There are lots of information about latest technology and how to get trained in them, like Best Hadoop Training In Chennai have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies Hadoop Training in Chennai By the way you are running a great blog. Thanks for sharing this blogs..

    ReplyDelete
  29. I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    SalesForce Training in Chennai

    ReplyDelete
  30. Pretty article! I found some useful information in your blog, it was awesome to read,thanks for sharing this great content to my vision, keep sharing..
    Unix Training In Chennai

    ReplyDelete
  31. This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post,thanks
    for taking the time to discuss this, I feel happy about it and I love learning more about this topic
    Android Training In Chennai In Chennai

    ReplyDelete
  32. I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job.
    SAP Training in Chennai

    ReplyDelete
  33. Oracle Training in chennai
    Thanks for sharing such a great information..Its really nice and informative..

    ReplyDelete
  34. Selenium Training in Chennai
    Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    ReplyDelete
  35. Data warehousing Training in Chennai
    I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly..

    ReplyDelete
  36. Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it, because you have explained the concepts very well. It was crystal clear, keep sharing..
    Websphere Training in Chennai

    ReplyDelete
  37. Oracle DBA Training in Chennai
    Thanks for sharing this informative blog. I did Oracle DBA Certification in Greens Technology at Adyar. This is really useful for me to make a bright career..

    ReplyDelete
  38. Angularjs training is essential for developing any single page web application. You have to learn Angularjs indepth to creating enterpirse SPA application.

    Angularjs Training | Angular.js Course | Angularjs Online Training | Angularjs Training in Chennai | AngularJS Interview Questions

    ReplyDelete
  39. 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