The definition constants of constants are case-sensitive by default, if define (' AA ', 20,true) denotes case-insensitive, the output name is generally capitalizedBOOL
Define ( string
$name
, Mixed
$value
[, BOOL
$case_insensitive
= False ]) ? The constant name must be caused by ' or ' because he is a string type Constants must be declared and judged using the "" ' output when the constant name can be used directlyThe value of a constant cannot be modified, and a permanent use is defined once1.define (' AA ', +);Echo AA;2.const aa= ' Chinese '; php5.3.0 after the new additionecho AA II, 1, isset () Check if the variable exists
$i=‘你好‘;
if(isset($i)){
echo ‘定义了变量‘;
}else{
echo ‘没有定义变量‘;
}
2, defined () check if constant exists
!defined (' AA ') && exit (' Termination of program ');
define (' AA ');
if (Defined (' AA ')) {
< Span class= "PLN" >echo ' defines constants ';
}else {
< Span class= "PLN" >echo ' no constants defined ';
} /code>
3,empty () if $i is undefined or $i=0, or null ' empty string is true, otherwise false
$i =1;
if (Empty ($i)) {
< Span class= "PLN" >echo ' $i is empty ';
}else {
< Span class= "PLN" >echo ' $i not empty ';
} The result is $i not empty
Third, exit (); Exit Exit (' program stops executing '); Indicates that the program terminates execution since then. Four, Magic constants
Use of single and double quotes
$age=20;
$str1=‘php-$age‘;//纯字符串
//echo gettype($str1);
echo $str1;
$str2="pdsjf-$age";//输出值,不引用变量直接输出hello就用‘‘
//echo gettype($str2);
echo $str2;
Array has subscript based on subscript output value, no subscript starting from 0 echo<pre>echo $ar 1[' sn '];//be sure to add single quotes, no errors, face questions
Echo </pre>
$ar1=array(‘sn‘=>‘李四‘,‘赵六‘,‘张三丰‘,200=>‘李勇‘,‘丽丽‘);
echo $ar1[1];
echo $ar1[‘sn‘];//一定要加单引号,不加错误,面试题
echo $ar1[201];
Indexed arrays make array indexes healthy and automatically assigned as numbers, such arrays are called indexed arrays
$arr 1= Array (10,20,30);
Associative arrays= = The association number$arr 2=[' hn ' and ' Henan ', ' bj ' = ' Beijing ', ' sh ' and ' Shanghai ']; php5.4 Support Later GetType () type of print output arrayEcho GetType ($arr 1), GetType ($arr 2);
Print out all the values in the array
方法一:用的多
foreach($arr2 as $v){ //用的多
echo $v.‘<br>‘;
}
方法二:
for($i=0;$i< count ($arr1);$i++){
echo $arr1[$i].‘<br>‘;
}
Key is the index key for the key array, which can be an integer integer or string value, which can be a value of an array of any type
foreach($arr2 as $k=>$v){
echo $k.‘==‘.$v.‘<br>‘;
}
PRINT_R the structure of the print output array
Print_r ($ar 1);
The most commonly used array traversal output mode, the Foreach Loop statement
foreach($ar1 as $k=>$v){
//echo $v.‘<br>‘; //输出值
echo $k.‘==>‘.$v.‘<br>‘;
//echo $k.‘<br>‘; // 输出下标 $v=>$k 可以换位置
}
Is_array ($r); is the array echo is_array ($r) judged? ' is an array ': ' is not an array '; In_array (' A ', $r); Do you judge if A is in the "Echo In_array (' A ', $r)? ' A is in the array ': ' A is not in the array ';Range ()Divide the interval quickly to generate an array of 1 intervals, which can be 2,3,4 ... $arr =range (' A ', ' Z ', 1);p Rint_r ($arr);explode ()Splitting a string into an array by symbol (,) is not recommended for $str= ' a,b,v,d '; $arr =explode (', ', $str);p Rint_r ($arr);implode ()The array is combined into a string $str=array (1,5,6,3) according to the split symbol, $arr =implode ('-', $str); Echo $arr; Get the click path from where to interview questionsecho $_server[' Http_referer '];
[Http_referer] = Http://localhost/aa.htmlselect count (*) from the log where rel like '%baidu% '; Echo ' <pre> ';p rint_ R ($_server); Read the clicked connection from the database which website did the customer come in from?$from = isset ($_server[' http_referver ')? $_server[' Http_referver ']:0;//0 means open directlyecho $from;//insert into log values ($from, Time), select COUNT (*) from log where rel. like '%baidu% ';
[server_name] + localhost get the domain name [server_addr] + 127.0.0.1 get the IP address of the server [server_port] = 80 [REMOTE_ADDR] = 127.0.0.1 Customer ID
echo $_server[' server_name ']. ' <br> '; Echo $_server[' server_addr ']. ' <br> '; Echo $_server[' server_addr ']. ' <br> '; all caps required
$a =$_server;echo $a [' remote_addr ']; It's best not to use it this way, it's easy to create variable confusion
From for notes (Wiz)
04PHP base-constant definition output 04PHP base-array definition and use