PHP Introductory tutorials in the operator and control structure of the flow of detailed _php tips

Source: Internet
Author: User

This article describes the operator and control structure flow of the introductory PHP tutorial. Share to everyone for your reference, specific as follows:

demo1.php

<?php
  $username = "Chaoyv";
  echo "His name is $username!";
  $username 2 = "Wu-ran";
  echo "His name is $username 2!";
  echo "<br/>";
  echo "His name is". $username 2. ", read who asked the chant, \ n water Fall fragrance floating. ";
  echo "<br/>";
  echo "His name is". $username 2. ", read who asked you to recite, \ t water fall 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 null
////identity must be the same data type////
$a = = $b Return is a false, false
//echo! ( $a = = = $b);  What does 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 the errors.
  //$a = 100/0; Warning:division by zero in C:\AppServ\www\Basic3\Demo5.php 2
  $a = @ (100/0);
  echo $a;
? >

demo6.php

<?php
  //if condition judgment statement
  $userAge =;
  The parentheses following the if is a Boolean expression, and the result returned is 1 or null
  //{} block statements
//if ($userAge >18) {
//   echo ' success ';
}
  //If ... Otherwise
//if ($userAge >18) {
//   echo ' success ';
}else{
//   echo ' failure ';
}
  //Multiple line
  if ($userAge <18) {
    echo ' <18 ';
  } ElseIf ($userAge <30) {
    echo ' <25 ';
  } else{
    echo ' through ';
  }
? >

demo7.php

<?php
  //Multiple line
  //break exit problem, called Midway exit this condition to judge
  $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 judging 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 + +) {////////   if ($i ==5) {
/     /break ;//exit loop
//   }
//   echo $i. ' <br/> ';
}
//for ($i = 0; $i <10; $i + +) {///////   if ($i ==5) {
//     exit //exit the entire program
//   }
//   echo $i. ' <br/> ';
}
//Echo ' I will also execute ';
  for ($i = 0; $i <10; $i + +) {
    //In this loop nested an IF judgment statement
    if ($i ==5) {
      continue;//exits the current loop and continues the next loop OK
    }
    echo $i. ' <br/> ';
>

More about PHP Interested readers can view the site topics: "Introduction to PHP Basic Grammar", "PHP operation and operator Usage Summary", "PHP object-oriented Program Design Primer", "PHP Network Programming Skills Summary", "PHP string (String) Usage Summary", " Introduction to PHP+MYSQL Database operations and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design.

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.