例子1,使用strlen获得长度,substr提取前5个字符:
$str = '123456789'if (strlen($str)>5) $str=substr($str,0,5) . '...'
echo $str
例子2,使用explode拆分IP,然后组装:
$ip = '192.168.0.1'list($ip1,$ip2,$ip3) = explode('.',$ip)
$ip = "*-*-$ip3-$ip4"
echo $ip
$arr = array(array(1,2,3),
array("a","b","c")
)
//在数组尾部添加元素
$arr[]=array(11,22,33)
print_r($arr)
这是输出的结果!
Array(
[0] =>Array
(
[0] =>1
[1] =>2
[2] =>3
)
[1] =>Array
(
[0] =>a
[1] =>b
[2] =>c
)
[2] =>Array
(
[0] =>11
[1] =>22
[2] =>33
)
)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)