PHP Introductory tutorial operator and control structure flow

Source: Internet
Author: User
Tags first string true true
This article describes the PHP introductory tutorial operator and control structure flow. Share to everyone for your reference, as follows:

demo1.php

<?php  $username = "Chaoyv";  echo "His name is $username!";  $username 2 = "WU";  echo "His name is $username 2!";  echo "<br/>";  echo "His name is". $username 2. ", read who asked June chanting, \ \ \ \ \ \ \ \ \ \ \" ";  echo "<br/>";  echo "His name is". $username 2. ", read who asked June chanting, \ t water fell fragrance floating. ";  Echo ' His name is $username 2! ';//Cannot parse $username 2?>

demo2.php

<?php  $a = 5;  $b = 6;//$c = $a + $b,//Echo $c,//$a + = $b;//$a = $a + $b;//echo $a;//$a =++ $b;//$b = $b +1//echo $a;  7//echo $b;  7  $a = $b + +;  echo $a;  6  echo $b;//7?>

demo3.php

<?php//$a = 5;//$b = ' 5 ';////on the Web page (True True) is the embodiment of 1, the false embodiment is empty///identity must be the same data type///$a = = = $b Return is a fake, false//Echo! ($a = = = $b);  What will this print out?  $a = 5;  $b = 5;  $c = ($a = = $b);  echo $c;  $d = 8;  $e = 7;  $f = ($d = = $e);  echo $c && $f;  echo $c | | $f;? >

demo4.php

<?php  $total =;  Ternary operator  //If the judgment is true, then the whole returns the first string, otherwise the second string  $sum = $total >50? ' Success ': ' Failure ';  Echo $sum;? >

demo5.php

<?php  //In the development process, it is best to expose errors.  //$a = 100/0; Warning:division by zero in C:\AppServ\www\Basic3\Demo5.php on line 2  $a = @ (100/0);  echo $a;? >

demo6.php

<?php  //if conditional judgment statement  $userAge =;  The parentheses after the if is a Boolean expression that returns a result of 1 or an empty  //{} block statement//if ($userAge >18) {//   echo ' success ';/}  //If ... otherwise//if ($userAge >18) {//   echo ' success ';//}else{//   echo ' failure ';/}  //Multi  -line if ($userAge <18) {    Echo ' <18 ';  } ElseIf ($userAge <30) {    echo ' <25 ';  } else{    echo ' through ';  }? >

demo7.php

<?php  //Multi  -line//break exit problem, called Midway exit this condition judgment  $weekday = 3;  Switch ($weekday) {case    1:      echo ' Today Monday ';      break;    Case 2:      echo ' Today Tuesday ';      break;    Case 3:      echo ' Today Wednesday ';      break;    Case 4:      echo ' Today Thursday ';      break;    Default:      echo ' not clear ';  }? >

demo8.php

<?php  //while Loop  //When the expression is false, exit the loop  $a = ten;  while ($a > 0) {    echo $a;    $a--;    Echo ' <br/> ';  }? >

demo9.php

<?php  //for for  ($a =10; $a >0; $a-) {    echo $a;    Echo ' <br/> ';  }? >

demo10.php

<?php  //do  while $a = ten;  do{    echo $a;    Echo ' <br/> ';    $a--;  } while ($a >0);? >

demo11.php

<?php//for ($i = 0; $i <10; $i + +) {////   in this loop nest an if judgment statement//   if ($i ==5) {//     break;//exit loop//   }//   echo $i. ' <br/> ';//}//for ($i = 0; $i <10; $i + +) {////   within this loop nested an IF Judgment statement//   if ($i ==5) {//     exit ///exit the entire program//   }//   echo $i. ' <br/> ';//}//echo ' I'll do it ';  for ($i = 0; $i <10; $i + +) {    //within this loop, nest an if judgment statement    if ($i ==5) {      continue;//exits the current loop and continues the next loop OK    }    echo $i. ' <br/> ';  }? >

I hope this article is helpful to you in PHP programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.