Home > Article > Backend Development > PHP sample code for filtering the first character of an array
phpIn the array, the array needs to be filtered by the first character. This is achieved through the following code. Friends in need can refer to the
code as follows:
<?php $array = array( 'abcd', 'abcde', 'bcde', 'cdef', 'defg', 'defgh' ); $str = '~'.implode('~',$array).'~'; $word = $_GET['word']; //url = xxx.php?word=a preg_match_all("/~({$word}(?:[^~]*))/i",$str,$matches); var_dump($matches[1]); //输出 //array(2) { [0]=> string(4) "abcd" [1]=> string(5) "abcde" } //End_php
The above is the detailed content of PHP sample code for filtering the first character of an array. For more information, please follow other related articles on the PHP Chinese website!