Abandoned fish--how long does PHP take to get from getting started to giving up? 7

Source: Internet
Author: User

Today's Lesson: PHP 3-Day Foundation Consolidation video Tutorial "Yan 18"

1, 99 multiplication table

for ($i =1; $i <= 9; $i + +) {//Output 1-9echo $i, ' <br/> ';} or ($i =1; $i <= 9; $i + +) {//Output 1-9echo $i, '----'; for ($j =1; $j < $i; $j + +) {//Judgment output echo $j, ' &nbsp; ';} echo ' <br/> ';} for ($i =1; $i <= 9; $i + +) {for ($j =1; $j <= $i; $j + +) {echo $j, ' * ', $i, ' = ', $j * $i, ' &nbsp;&nbsp;&nbsp; '; /output}echo ' <br/> ';}

2, hundred money to buy hundred chickens

*/* Our ancient mathematician Zhang Chujian in the Book of "Zhang Chujian", put forward "hundred chicken Problem": Chicken Weng One, worth five, chicken mother one, worth three, chickens three, valuable one. Hundred money buys hundred chicken, asks the chicken Weng, the chicken mother, chickens each geometry? */for  ($g =1;  $g  <= 100 ;  $g + +)  { for  ($m =1;  $m  <=  100 ;  $m + +)  { for  ($x =1;  $x  <= 100 ;  $x + +)  {  if  ($g  +  $m  +  $x  == 100)  &&  ($g  * 5  +  $m  * 3 +  $x/3)  == 100  {echo  ' male   female   small ', $g, ' &nbsp; ', $m, ' &nbsp; ', $x, ' &nbsp; ', ' only <br /> ';}}} echo  ' <br /> ';for  ($g =1;  $g  <= 20 ;  $g +)  {//optimized   for  ($m =1;  $m  <= 33 ;  $m + +)  {  $x  = 100 -  $g  -  $m;if  (($g  +  $m  +  $x  == 100)  &&  ($g  *  5 +  $m  * 3 +  $x/3)  == 100  {echo  ' male   female &nbsp, small each ', $g, ' &nbsp; ', $m, ' &nbsp; ', $x, ' &nbsp; ', ' only <br /> ';}}} 

3. Functions

A function is a well-encapsulated code that can be called at any time, function t () {echo "Hello"; echo "World"; echo "!<br/>";} T (); t (); Echo ' <br/> '; function h ($a, $b) {$c = $a + $b; $d = $a * $b; Echo $c, ' <br/> '; echo $d;} H (+); Echo ' <br/> '; function h2 ($a, $b) {//return value $c = $a + $b; return $c;} $d = h2 (4,5); Echo $d;

4. Function definition Format

/*function function name ([parameter] [parameter]) {//EXECUTE statement//return;} naming rules: For functions, naming rules and variables, but functions are not case-sensitive */

5. Function execution and return process

echo ' <br/> '; function A () {//All statements are executed or a return statement is encountered, and functions return echo "AAAAA <br/>";} echo "B<br/>"; a (); echo "string"; Echo ' <br/> '; function B () {echo "1"; echo "2"; return ' 3 '; echo "4"; echo "5"; re Turn ' 6 ';} $a = B (); Echo $a; echo "b<br/>"; function C () {return 1,4;//return can return no value, or only one value}

6. Function Transfer method

echo "<br/>"; function d ($a) {$a + = 1;} $b = 3;d ($b),//$b, equivalent to the value of descending $b is assigned to $ A. And a $ A is the function inside the value, how to change is not related to the outside Echo $b, ' <br/> '; function d2 (& $a) {$a + = 1;} $b = 5;d2 ($b); echo $b;//$a and $b point to the same address, which is not recommended because the inner statement of the function affects external variables and destroys the encapsulation of the function.

7. Function scope

echo "<br/>"; function e () {//In the PHP page, the declared variable is called a global variable, and the function declares a local variable called the Echo $a;} E (); echo "<br/>";//DECLARE global variable globalfunction f () {global $a; echo $a;} f (); echo "<br/>";//Super global variable, in any part of the page, including functions, methods, etc., can directly access function g () {Print_r ($_get);} g (); echo "<br/>";

Sleep, another #我要上首页 # m M I want the first page, is this the way to play??

This article from "A Big big waste fish" blog, declined reprint!

Abandoned fish--how long does PHP take to get from getting started to giving up? 7

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.