Home >Backend Development >PHP Tutorial >PHP study notes 1-constants, functions, php study notes 1-constants_PHP tutorial
Constant: Use const (php5) declaration, can only be assigned once, versions below php5 use define ;
<span>1</span> <?<span>php </span><span>2</span> <span>const</span> THE_VALUE = 100;<span>//</span><span>PHP5中才有const</span> <span>3</span> <span>echo</span><span> THE_VALUE; </span><span>4</span> <span>5</span> <span>define</span>('THE_VALUE',200);<span>//</span><span>低于PHP5的老版本可以使用define</span> <span>6</span> <span>echo</span> THE_VALUE;
Function: a code block that wraps many functions;
Advantages: easy to call elsewhere
1 bbbb25bf325e6580d37940196b671684'; 6 echo 'Hello World!'; 7 echo '076402276aae5dbec7f672f8f4e5cc81'; 8 } 9 traceHelloPHP(); 10 11 //Another way to execute the function 12 $func = 'traceHelloPHP';//Pass the function as a parameter, e.g. callback method 13 $func(); 14 15 //Incoming parameters of the function--single incoming parameter 16 function sayHelloTo($name){ 17 echo 'Hello '.$name.'076402276aae5dbec7f672f8f4e5cc81'; 18 } 19 sayHelloTo('Vito'); 20 21 //Incoming parameters of the function--multiple incoming parameters 22 function traceNum($a,$b){ 23 // echo 'a = '.$a.', b = '.$b.'076402276aae5dbec7f672f8f4e5cc81'; 24 echo "a = $a,b = $b";// is better Simple way to write 25 } 26 traceNum(2,3); 27 28 function add($a,$b){ 29 return $a $b;//return value 30 } 31 echo add(10,2); View Code