04PHP base-constant definition output 04PHP base-array definition and use

Source: Internet
Author: User
Tags array definition constant definition

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
 
   
  
  1. $i=‘你好‘;
  2. if(isset($i)){
  3. echo ‘定义了变量‘;
  4. }else{
  5. echo ‘没有定义变量‘;
  6. }

    2, defined () check if constant exists
!defined (' AA ') && exit (' Termination of program ');
 
   
  
  1. define (' AA ');
  2. if (Defined (' AA ')) {
  3. < Span class= "PLN" >echo ' defines constants ';
  4. }else {
  5. < Span class= "PLN" >echo ' no constants defined ';
  6. } /code>
         3,empty () if $i is undefined or $i=0, or null ' empty string   is true, otherwise false
 
   
  
  1. $i =1;
  2. if (Empty ($i)) {
  3. < Span class= "PLN" >echo ' $i is empty ';
  4. }else {
  5. < Span class= "PLN" >echo ' $i not empty ';
  6. } 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
  
 
  1. $age=20;
  2. $str1=‘php-$age‘;//纯字符串
  3. //echo gettype($str1);
  4. echo $str1;
  5. $str2="pdsjf-$age";//输出值,不引用变量直接输出hello就用‘‘
  6. //echo gettype($str2);
  7. 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>
  
 
  1.      
        
    1. $ar1=array(‘sn‘=>‘李四‘,‘赵六‘,‘张三丰‘,200=>‘李勇‘,‘丽丽‘);
    2. echo $ar1[1];
    3. echo $ar1[‘sn‘];//一定要加单引号,不加错误,面试题
    4. 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
  
 
  1. 方法一:用的多
  2. foreach($arr2 as $v){ //用的多
  3. echo $v.‘<br>‘;
  4. }
  5. 方法二:
  6. for($i=0;$i< count ($arr1);$i++){
  7. echo $arr1[$i].‘<br>‘;
  8. }
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
 
   
  
  1. foreach($arr2 as $k=>$v){
  2. echo $k.‘==‘.$v.‘<br>‘;
  3. }
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
  
 
  1. foreach($ar1 as $k=>$v){
  2. //echo $v.‘<br>‘; //输出值
  3. echo $k.‘==>‘.$v.‘<br>‘;
  4. //echo $k.‘<br>‘; // 输出下标 $v=>$k 可以换位置
  5. }
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

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.