php

手机格式验证

$phonenumber = '13712345678';  
if(preg_match("/^1[34578]{1}\d{9}$/",$phonenumber)){  
    echo "是手机号码";  
}else{  
    echo "不是手机号码";  
}  

排序

sort() 函数用于对数组单元从低到高进行排序。
rsort() 函数用于对数组单元从高到低进行排序。
asort() 函数用于对数组单元从低到高进行排序并保持索引关系。
arsort() 函数用于对数组单元从高到低进行排序并保持索引关系。
ksort() 函数用于对数组单元按照键名从低到高进行排序。
krsort() 函数用于对数组单元按照键名从高到低进行排序。
链接数组
<?php  
$name = array("apple", "banana", "orange");  
$color = array("red", "yellow", "orange");  
$fruit = array_combine($name, $color);  
print_r($fruit);  
  
// output  
// Array ( [apple] => red [banana] => yellow [orange] => orange )  
?>  
拆分数组
<?php  
  
$fruits = array("Apple", "Banana", "Orange", "Pear", "Grape", "Lemon", "Watermelon");  
$subset = array_slice($fruits, 3);  
print_r($subset);  
  
// output  
// Array ( [0] => Pear [1] => Grape [2] => Lemon [3] => Watermelon )  
?> 

<?php  
  
$fruits = array("Apple", "Banana", "Orange", "Pear", "Grape", "Lemon", "Watermelon");  
$subset = array_slice($fruits, 2, -2);  
print_r($subset);  
  
// output  
// Array ( [0] => Orange [1] => Pear [2] => Grape )  
?>  
php在数组开头插入元素函数array_unshift()用法
<?php
$queue = array("orange", "banana");//定义数组
array_unshift($queue, "apple", "raspberry");//向数组插入元素
print_r($queue);
?>
接合数组 array_splice()
<?php  
  
$fruits = array("Apple", "Banana", "Orange", "Pear", "Grape", "Lemon", "Watermelon");  
$subset = array_splice($fruits, 4);  
  
print_r($fruits);  
print_r($subset);  
  
// output  
// Array ( [0] => Apple [1] => Banana [2] => Orange [3] => Pear )   
// Array ( [0] => Grape [1] => Lemon [2] => Watermelon )  
?>  

 

substr_replace() 函数用于把字符串的一部分替换为另一个字符串,返回混合类型。
<?php echo substr_replace('abcdef', '###', 1); //输出 a### echo substr_replace('abcdef', '###', 1, 2); //输出 a###def echo substr_replace('abcdef', '###', -3, 2); //输出 abc###f echo substr_replace('abcdef', '###', 1, -2); //输出 a###ef ?>
str_replace() 函数使用一个字符串替换字符串中的另一些字符,返回混合类型。 echo str_replace(
"world","earth","Hello world!"); //输出 Hello earth!

 

posted @ 2016-08-05 11:40  伊人世界  阅读(193)  评论(0编辑  收藏  举报
Fork me on GitHub