How to remove special symbols from elements in a php array: First, the array must be a string array. If not, use the [strval()] function to convert each array element into a string; then use the [preg_replace] function Just replace [-] with an empty string.
How to remove special symbols from elements in a php array:
First of all, your array must be a string array. If not, you want to use the strval()
function to convert each array element into a string,
Then, use the preg_replace
function to replace '-' with a null character String, that’s it.
The complete php program is as follows:
<?php $arr=array('2015-01','2015-02','2015-03','2015-04'); for($i=0;$i<count($arr);$i++){ $arr[$i]=preg_replace('#\-#','',$arr[$i]); } print_r($arr); ?>
Running result:
Array ( [0] => 201501 [1] => 201502 [2] => 201503 [3] => 201504 )
Related free learning recommendations: php programming (video)
The above is the detailed content of How to remove special symbols from elements in php array. For more information, please follow other related articles on the PHP Chinese website!