Common methods of regular expressions:
#preg_replace (Regular expression, "X", $STR) replaces the regular expression in the string with the X-
#preg_spilt (regular expression, $str) separates the string from where it satisfies the regular expression, returning the array
#preg_match (regular expression, $STR, array) extracts the first of the string Str that satisfies the regular expression into the array
#preg_match_all (regular expression, $STR, array) extracts all the regular expressions in the string str into the array
Array
#索引数组Definition: statement definition $a =array (1,2,3,4 ...) Assignment definition $a [0]=1; $a [1]=2;
#关联数组 definition: $a =array ("One" =>5, "one" =>6 ...)
#特点: Can store any type of data, the length of the array can be changed
#for循环遍历数组: cannot traverse associative array
$a=array(1,2,3,4); for ($i= 0; $i<count($a); $i+ +) {echo$a[$i]. " <br> ";}
#foreach遍历数组: You can traverse associative arrays
$a=array(1,2,3,4); foreach ($aas$t) { echo$t. <br> ";}
#foreach遍历数组: can get array element designator and value
$a=array("A" =>1, "B" =>2, "C" =>3, "D" =>4); foreach ($aas$i= +$j) {echo$i. " =". $j. " <br> ";}
#var_dump (each ($a)); Var_dump (each ($a)); ...//Returns the code and value of the element inside the array, each time it is executed, takes an element, executes the second, and the second element ...
#list函数, the special function that appears to the left of the equals sign
List ($a, $b, $c, $d ...) = array//assigns the value inside the array to the variable in parentheses, the number of variables in parentheses must <= the number of array elements
#each, the LIS function is combined to iterate through the array.
$a=array("A" =>1, "B" =>2, "C" =>3, "D" =>4); while (list($i,$j) =each ($a)) { echo$i ." =". $j. " <br> ";}
#current (array)//Take the current (value) of the array element
#key (array)//take an array of elements of key (codename)
#next (array)//add pointer to one
#prey (array)//reduce the pointer by one
#end (array)//point pointer to last
#reast (array)//Reset the pointer
#用指针遍历数组
$a=array("A" =>1, "B" =>2, "C" =>3, "D" =>4); Do { echocurrent ($a). " =". Key ($a). " <br> ";} while (next($a))
#获取表单数据 $_post &_get (address bar can be seen, there is a length limit)
About functions of arrays
#判断数组是否存在某个值 In_array ("element", array)
#翻转数组并返回数组 Array_reverse (Array)
#返回数组的长度 count (Array)
#去掉重复元素的索引和值 Array_unique (Array)//execute to rearrange arrays
#删除数组元素的索引和值 unset (array [x])//execute to rearrange the array
#重新排列去重的数组索引 Array_value (Array)
#合并数组 Array_merge (arrays, arrays ...)
#往数组里面追加元素 Array_push (array, Element)//new element added at the end
#定义二维数组 $a =array (array (), array (), array (), array (), array (), array (), Array () ... )
51st Day Class regular expressions and arrays