Home  >  Article  >  Backend Development  >  How to remove special symbols from php array

How to remove special symbols from php array

藏色散人
藏色散人Original
2020-07-09 13:08:522935browse

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]);".

How to remove special symbols from php array

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:

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!

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