Beginners to learn PHP development should be mastered several sections of the Essence Code _php tutorial

Source: Internet
Author: User
Tags define function learn php

Classic Loop examples



Classic Loop examples


for ($counter = 1; $counter <= 6; $counter + +)//cycle 6 times
{
Print ("counter is $counter
"); Print 6 times
}
?>


For advanced use


For advanced use


/*
* * Print the necessary explanatory text
*/
Print (" How many days away from Monday?") ");
Print ("

      ");
      for ($currentDate = Date ("U");//define $currentdate time format
      Date ("L", $currentDate)! = "Monday"; Determine if the current system time is Monday
      $currentDate + = (60 * 60 * 24))//Current time plus 1 days
      {
      /*
      * * Print time name
      */
      Print ("
    1. " . Date ("L", $currentDate). "");
      }

      Print ("

");
?>

Simple invocation of the function:



simple functions



!--? function Printbold ($inputText)//define function Printbold ()
{
Print (" ". $inputText. ""); Printing $inputtext
}
Print ("This line is not aggravating!")
"); Direct Print string
Printbold ("This line is aggravating!!! "); Call function Printbold ()
Print ("
");
Print ("This line is not aggravating!")
"); Direct print string
?



function with return value


function with return value



!--? function Makebold ($inputText)//define function Makebold () functions
{
$boldedText = " ";
$boldedText. = $inputText;
$boldedText. = "
";
return ($boldedText);//return variable $boldedtext
}
Print ("This line is not aggravating!!!")
"); Print the string directly
print (Makebold ("This line is aggravated!!! ") . "
");//Call Function Makebold () function
Print (" This line is not aggravating!!! ")
"); Direct print string
?


Functions with default parameters


Functions with default parameters



function printcolored ($Text, $Color = "BLACK")//define function functions
{
Print ("$Text"); Get the contents and colors of a string
}
Printcolored ("This is the black color of the word!") "); Calling function functions
Print ("

");
Printcolored ("This is the blue color of the word!") "," Blue "); Calling function functions
Print ("
");
?>


Determines whether an integer is



judging integers


!--? function Checkinteger ($Number)
{
if ($Number > 1) The
{
/* integer minus 1 is still an integer */
Return (Checkinteger ($Number-1));
}
ElseIf ($Number < 0)
{
/* for a negative number, */
/* Can parse its absolute value */
Return (Checkinteger (( -1) * $Number-1));//Take absolute value, Parse negative numbers by integer
}
Else
{
if (($Number > 0) and ($Number < 1))
{
Return ("Of course not");
}
Else
{
/* 0 and 1 are integers */
/* Based on relevant mathematical definitions */
Return ("yes");
}
}
}
Print (" 0 is an integer? " .
Checkinteger (0). "
");
Print (" 7 is an integer?) " .
Checkinteger (7). "
");
Print (" 3.5?"). " . Checkinteger (3.5). "
");
Print (" so-5? " . Checkinteger (-5). "
");
Print (" and-9.2? " . Checkinteger (-9.2). "
");
?


Initialize array



Initializing an array


$monthName = Array (1=> "January", "February", "March",//initialization of an array
"April", "may", "June", "July", "August",
"September", "October", "November", "D

http://www.bkjia.com/PHPjc/486620.html www.bkjia.com true http://www.bkjia.com/PHPjc/486620.html techarticle Classic Loop Example HTML HEAD TITLE Classic Loop Example/title/head BODY for ($counter = 1; $counter = 6; $counter + +)//loop 6 times {print ("Bcounter I s $counter/bbr "); Print 6 times} ...

  • Related Article

    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.