PHP getting started tutorial-detailed explanation of the operator and control structure process, Getting Started tutorial Operator

Source: Internet
Author: User
Tags exit in

PHP getting started tutorial-detailed explanation of the operator and control structure process, Getting Started tutorial Operator

This document describes the operator and control structure of the PHP getting started tutorial. We will share this with you for your reference. The details are as follows:

Demo1.php

<? Php $ username = "chaoyv"; echo "His name is $ username! "; $ Username2 =" Wu zhiran "; echo" His name is $ username2! "; Echo" <br/> "; echo" His name is ". $ username2.", who asked me? \ n. "; Echo" <br/> "; echo" His name is ". $ username2.", who will read this question? \ t water is refreshing and refreshing. "; Echo 'his name is $ username2! '; // Unable to parse $ username2?>

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'; // the embodiment of true on the webpage is 1, false: NULL // constant. The required data type is also the same. // $ a ===$ B returns a false, false // echo! ($ A ===$ B); // What does this print? $ 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 = 80; // ternary operator // if it is true, the first string is returned as a whole; otherwise, the second string $ sum = $ total> 50? 'Success': 'failed'; echo $ sum;?>

Demo5.php

<? Php // it is best to expose all errors during development. // $ 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 condition judgment statement $ userAge = 25; // The brackets after if are boolean expressions, the returned result is 1 or null // {} BLOCK statement // if ($ userAge> 18) {// echo 'success'; //} // if... Otherwise // if ($ userAge> 18) {// echo 'success'; //} else {// echo 'failed '; /// multiline if ($ userAge <18) {echo '<18';} elseif ($ userAge <30) {echo' <25 ';} else {echo 'passed';}?>

Demo7.php

<? Php // multi-line // break exit problem, which is called exit in the middle. The condition $ weekday = 3; switch ($ weekday) {case 1: echo 'today Monday'; break; case 2: echo 'tuesday '; break; case 3: echo 'wedday'; break; case 4: echo 'thursday'; break; default: echo 'unclear ';}?>

Demo8.php

<? Php // while LOOP // when the expression is determined to be false, exit the loop $ a = 10; while ($ a> 0) {echo $ a; $ --; echo '<br/>';}?>

Demo9.php

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

Demo10.php

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

Demo11.php

<? Php // for ($ I = 0; $ I <10; $ I ++) {//// nested an IF judgment statement in this loop // if ($ I = 5) {// break; // exit the loop halfway //} // echo $ I. '<br/>'; //} // for ($ I = 0; $ I <10; $ I ++) {// nested an IF judgment statement in this loop // if ($ I = 5) {// exit; // exit the entire program //} // echo $ I. '<br/>'; //} // echo 'I will execute'; for ($ I = 0; $ I <10; $ I ++) {// nest an IF judgment statement in this loop if ($ I = 5) {continue; // exit the current loop and continue the next loop OK} echo $ I. '<br/>' ;}?>

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.