php method to remove symbols: first create a string array; then use the "preg_replace" function to replace the specified symbol with an empty string. The statement is "$arr[$i]=preg_replace(' #\-#','',$arr[$i]);".
Remove special symbols from elements in php array
First of all, your array must be a string array, if not you Use the strval() function to convert each array element into a string,
Then, use the preg_replace function to replace '-' with an empty string, and 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); ?>
Run result:
Array ( [0] => 201501 [1] => 201502 [2] => 201503 [3] => 201504 )
For more related articles, please visit PHP Chinese website!
The above is the detailed content of How to remove special symbols from php array. For more information, please follow other related articles on the PHP Chinese website!