20170930

作者: 雨y飘零久 | 来源:发表于2017-10-02 15:56 被阅读0次

    1.chr(ascii)

    从不同的 ASCII 值返回字符

    2.ord(string)

    返回 "S" 的 ASCII值

    3.list(var1,var2...)

    把数组中的值赋给一些变量

    <?php
    $my_array = array("Dog","Cat","Horse");
    
    list($a, $b, $c) = $my_array;
    echo "I have several animals, a $a, a $b and a $c.";
    ?>
    

    I have several animals, a Dog, a Cat and a Horse.

    4.php有8种数据类型

    四种标量类型:boolean (布尔型)integer (整型)float (浮点型, 也称作 double)string (字符串)两种复合类型:array (数组)object (对象)最后是两种特殊类型:resource (资源)NULL (NULL)运算符有:加减乘除,取模

    5.array_unshift(array,value1,value2,value3...)

    <?php
    $a=array("a"=>"red","b"=>"green");
    array_unshift($a,"blue");
    print_r($a);
    ?>
    

    Array ( [0] => blue [a] => red [b] => green )

    6.array_shift(array)

    <?php
    $a=array("a"=>"red","b"=>"green","c"=>"blue");
    echo array_shift($a);
    print_r ($a);
    ?>

    red Array ( [b] => green [c] => blue )

    7.heredoc和nowdoc的区别

    heredoc使用 <<< EOT 的标示符,而nowdoc使用 <<< 'EOT' 这样的标示符,其中nowdoc是PHP5.3引进的新技术,它包含了heredoc的语法,只是其中的内容绝对不会进行任何的转义和解释,是什么内容就是什么内容,不会解析PHP相关的内容

    • heredoc是动态的 nowdoc是静态的
    • heredoc类似多行的双引号 newdoc类似多行的单引号
    • heredoc是一种专门处理大段字符串的通用处理方案,而nowdoc是php为了弥补动态实现“heredoc”的效率问题而实现的“高效率”的静态版本

    8.range(low,high,step)

    返回包含 "0" 至 "50" 之间并以 10 递增的元素的数组:

    <?php
    $number = range(0,50,10);
    print_r ($number);
    ?>
    

    Array ( [0] => 0 [1] => 10 [2] => 20 [3] => 30 [4] => 40 [5] => 50 )

    9.shuffle(array)

    把数组中的元素按随机顺序重新排序

    10.compact(var1,var2...)

    <?php
    $firstname = "Bill";
    $lastname = "Gates";
    $age = "60";
    
    $result = compact("firstname", "lastname", "age");
    
    print_r($result);
    ?>
    

    Array ( [firstname] => Bill [lastname] => Gates [age] => 60 )

    11.array_chunk(array,size,preserve_key);

    把数组分割为带有两个元素的数组

    • preserve_key 可选。可能的值:
      • true - 保留原始数组中的键名。
      • false - 默认。每个结果数组使用从零开始的新数组索引。
    <?php
    $cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel");
    print_r(array_chunk($cars,2));
    ?>
    

    Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )

    12.array_slice(array,start,length,preserve)

    从数组的第二个元素开始取出,并仅返回两个元素

    <?php
    $a=array("red","green","blue","yellow","brown");
    print_r(array_slice($a,1,2));
    ?>
    

    Array ( [0] => green [1] => blue )

    13.array_diff(array1,array2,array3...);

    array3,... 可选。与第一个数组进行比较的其他数组。

    <?php
    $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
    $a2=array("e"=>"red","f"=>"black","g"=>"purple");
    $a3=array("a"=>"red","b"=>"black","h"=>"yellow");
    
    $result=array_diff($a1,$a2,$a3);
    print_r($result);
    ?>
    

    Array ( [b] => green [c] => blue )

    14.array_intersect(array1,array2,array3...)

    array3,... 可选。与第一个数组进行比较的其他数组。

    <?php
    $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
    $a2=array("e"=>"red","f"=>"black","g"=>"purple");
    $a3=array("a"=>"red","b"=>"black","h"=>"yellow");
    
    $result=array_intersect($a1,$a2,$a3);
    print_r($result);
    ?>
    

    Array ( [a] => red )

    15.array_search(value,array,strict)

    • strict 可选。如果该参数被设置为 TRUE,则函数在数组中搜索数据类型和值都一致的元素。可能的值:
      • true
      • false - 默认
        如果设置为 true,则在数组中检查给定值的类型,数字 5 和字符串 5 是不同的(参见实例 2)。

    在数组中搜索键值 5,并返回它的键名(注意 ""):

    <?php
    $a=array("a"=>"5","b"=>5,"c"=>"5");
    echo array_search(5,$a,true);
    ?>
    

    b

    16.array_splice(array,start,length,newarray)

    从数组中移除元素,并用新元素取代它
    把 length 参数设置为 0

    <?php
    $a1=array("0"=>"red","1"=>"green");
    $a2=array("0"=>"purple","1"=>"orange");
    array_splice($a1,1,0,$a2);
    print_r($a1);
    ?>
    

    Array ( [0] => red [1] => purple [2] => orange [3] => green )

    17.array_flip(array);

    反转数组中所有的键以及它们关联的值

    相关文章

      网友评论

          本文标题:20170930

          本文链接:https://www.haomeiwen.com/subject/thrnextx.html