美文网首页
PHP practice - chapter 1

PHP practice - chapter 1

作者: fuxiaotao | 来源:发表于2016-03-10 11:28 被阅读0次

    1. 多维数组排序 

    usort()  不保留key

    uasort() 保留key

    ksort($array, $sort_flags)              uksort($array, $key_compare_func)

    2. 自定义的排序函数,返回值:负数或者false意味着第一个参数排在第二个参数前面;正数或true表示第二个参数排在前面;值为0表示两个参数值相等。

    3. 递归函数:函数自己调用自己的行为。

    当处理过程具有不可预知的层次时,使用递归函数就很有必要了。

    两个需要注意的:

        a) 确保函数有一个退出的语句,到达某个条件,函数将终止对自身的调用,

        b) 从服务器资源的角度来说,递归函数的成本是比较高的。

    4. 静态变量让函数在多次被调用时记住变量的值。

    5. 匿名函数,一个没有名字的函数。创建匿名函数的特性是在5.3版本中新增并在5.4版本中进一步扩展的。

    6. printf, 可以设置输出的格式。

    sprintf 非常适合生成数据库查询语句,从而避免在代码中非常丑陋地使用混合SQL与变量。

    7. one more function,

    preg_replace(mixed $pattern, mixed $replacement, mixed $subject, int $limit, int $count)

    Perform a regular expression search and replace

    Returns:

    mixed preg_replace returns an array if the subject parameter is an array, or a string otherwise.

    If matches are found, the new subject will be returned, otherwise subject

    will be returned unchanged or &null; if an error occurred.

    相关文章

      网友评论

          本文标题:PHP practice - chapter 1

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