Home > Backend Development > PHP Problem > How to remove special symbols from elements in php array

How to remove special symbols from elements in php array

coldplay.xixi
Release: 2023-03-06 12:36:01
Original
2676 people have browsed it

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 php array

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(&#39;2015-01&#39;,&#39;2015-02&#39;,&#39;2015-03&#39;,&#39;2015-04&#39;);
 
for($i=0;$i<count($arr);$i++){    
 
 $arr[$i]=preg_replace(&#39;#\-#&#39;,&#39;&#39;,$arr[$i]);
 
}
 
print_r($arr); 
 
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template