来看看输出结果: 自己的函数调用运行时间为:9.3936920166E-005 S 标准的函数调用运行时间为:2.69412994385E-005 S 前者是后者的:3 倍! 多次刷新页面的话,可以发现标准函数的执行效率基本上是自己的函数的 3 倍!当然,标准的函数中使用了 PHP 的内置函数: str_split(),implode(),所以要比自己写函数快得多,对 str_split() 函数没有印象?来看看手册解释: str_split -- Convert a string to an array(将一个字符串转换成数组) 函数描述: array str_split ( string string [, int split_length] ) 复制代码 代码如下: Converts a string to an array. If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
Output may look like: 复制代码 代码如下: Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => F [7] => r [8] => i [9] => e [10] => n [11] => d ) Array ( [0] => Hel [1] => lo [2] => Fri [3] => end )