Home  >  Article  >  Backend Development  >  PHP custom functions & arrays

PHP custom functions & arrays

高洛峰
高洛峰Original
2017-02-18 17:21:451013browse

<?php
//生成随机数 和 时间函数
//echo rand();
//echo "<br>";
//echo rand(0,10);
//echo time();//时间戳
//2017-02-10 08:46:12
date_default_timezone_set("Asia/Shanghai");

//echo date("Y-m-d h:i:s");//默认转换当前时间
//echo date("Y-m-d h:i:s",&#39;1386688343&#39;);
//echo strtotime("2013-12-10 11:12:23");
//字符串的处理
//$str = &#39;Hello World!!!&#39;;
//echo strlen($str);
//$str1=&#39;Abc&#39;;
//$str2=&#39;abc&#39;;
//echo strcmp($str1,$str2);
//echo strcasecmp($str1,$str2);
//echo strtoupper($str2);
//echo strtolower($str1);

//$str = "a|B|c|d";

//$str1 = explode("|",$str);
//echo implode("&",$str1);

//echo substr($str,1,3);
//echo str_replace("|","&",$str);
//echo substr_replace($str,"%",1,1);
//$str = "hello3 world4 ashdf223sdfa2323sd45454";
//preg_match("/\d/",$str,$str2);
//preg_match_all("/\d/",$str,$str3);
//var_dump($str3);
//$str4 = preg_replace("/\d/", "数字", $str);
//var_dump($str4);
//$str5 = preg_split("/\d/",$str);
//var_dump($str5);
//function hansm($v)
//{
//    $v++;
//    return $v;
//}
//$temp = hansm(5);
//echo $temp;
//function test($a, $b = 3)
//{
//    return $a + $b;
//}
//
//echo test(2,4);
//function test2()
//{
//    $arr = func_get_args();
//    return $arr;
//}
//var_dump(test2(2,3));
//$arr = array();
//var_dump($arr);

$arr = array(&#39;x&#39;, &#39;y&#39;, 34);

$arr2 = array(
    &#39;x&#39; => &#39;a&#39;,
    &#39;y&#39; => &#39;b&#39;,
    &#39;z&#39; => &#39;c&#39;,
    9 => 35
);
//$arr_merge=array_merge($arr,$arr2);
//var_dump($arr_merge);
//echo $arr2[2];
//var_dump($arr2);
//array_push($arr2,&#39;xxx&#39;);
//var_dump($arr2);
//var_dump(in_array(&#39;v&#39;,$arr2));
//$arr_reverse = array_reverse($arr2);
//var_dump($arr_reverse);
//unset($arr2);
//$ar2 = null;
//var_dump($arr2);
//for($i=0;$i<count($arr2);$i++)
//{
//
//}
foreach ($arr2 as $k)
{
    var_dump($v);
}
foreach ($arr2 as $k=>$v){
    var_dump($arr2[$k]);
}
//echo $v;

For more articles related to PHP custom functions & arrays, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php array pointerNext article:php array pointer