PHP study notes 1-constants, functions, php study notes 1-constants
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;
Copy after login
Function: a code block that wraps many functions;
Advantages: easy to call elsewhere
1 php
2
3 function traceHelloPHP(){
4 echo 'Hello PHP!'
;
5 echo '
'
;
6 echo 'Hello World!'
;
7 echo '
'
;
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.'
'
;
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.'
';
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
http://www.bkjia.com/PHPjc/1022594.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1022594.htmlTechArticlePHP study notes 1-constants, functions, php study notes 1-constants Constants: use const (php5) declaration, Can only be assigned once, versions below php5 use define; 1 ? php 2 const THE_VALUE...