PHP functions and small knowledge points

Source: Internet
Author: User
Tags echo date

<?PHP//Statement//Branch statement/*$a =5; if ($a ==5) {echo "equal";} else{echo "Budeng";}*///If//if...else//if...else. Nesting of if//if/*switch ($a) {case 1:echo "111"; Break    Case 2:echo "222";    Break    Case 3:echo "333";    Break    Case 4:echo "444";    Break    Default:echo "Default";    Break }*///Looping Statements/*For ($i =0; $i <10; $i + +) {echo $i. " <br> ";} $a =10;while ($a >0) {echo $a. "    <br> "; $a--;}*///function Four elements: return type, function name (initial capitalization), parameters, function body/function definition mode/*function Show () {echo "Hello";} Call function Show ();*///parametric functions/*function Show ($a, $b) {echo $a + $b;} Show (3,4,5)*///functions with default values/*function Show ($a =5, $b =5) {echo $a + $b;} Show ();*///functions with variable parameters/*function Show () {Func_get_args ();}    Gets the parameter $sum=0 of the function;     for ($i =0; $i <count ($attr)), $i + +)//Func_num__args () Gets the number of parameters {$sum = $sum + $attr [si]}; echo $sum;}*///functions that have return values/*function Show () {return "AAAA";} Echo Show ();*//*echo rand (0,100);//random number generation function*///Echo time ()///Date time taken is timestamp//echo date ("Y-m-d h:i:s" and Time ());//Format datetime//date_default_timezone_set (' PRC '); Method//echo Date ("Y-m-d h:i:s", Time ()),//echo strtotime ("2016-5-6"); Convert datetime format to timestamp//string processing function////$a = "Hello";//echo strlen ($a); Returns the string length *****//echo strcmp ("Hello", "Hello"); Compares two strings for equality, case-sensitive//echo strcasecmp ("AA", "AA"),//Compare two strings for equality, case-insensitive//echo strtolower ("HELLO");//convert string to lowercase *****/ /echo strtoupper ("Hello");//convert string to uppercase *****//$str = "Hello|world|join|on";//var_dump (Explode ("|", $str)); Depending on the delimiter, split the string, and the return is an array of *****//$attr =array ("AAA", "BBB", "CCC")//echo implode ("|", $attr); $str = "Hello|world|join|on";//echo substr_replace ($str, "AAA", 0,5)//Replace the string (replacing a position, where the position is determined by a subsequent parameter) *****//echo Str_replace ("L", "a", $str);//Find and replace *****//echo substr ($STR, 0,5); Intercept string *****//Some small knowledge points/*$a = "join"; $s 1= "hello\" {$a}world ";//1. Double quotes can use escape characters, single quotes cannot be used, output//2 as-is. Double quotes inside can parse variable, single quotation mark does not echo $s 1." <br/> "; $s 2= ' hello\" {$a}world '; Echo $s 2; Both single and double quotation marks can define a string,*///Defining a String (block)$str=<<<STR<div style= "Background-color:pink; color:white;width:100px;height:30px ">hello</div>STR;Echo $str; ?>

PHP functions and small knowledge points

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.