PHP sample code for filtering the first character of an array

怪我咯
Release: 2023-03-12 22:30:02
Original
1153 people have browsed it

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( 
&#39;abcd&#39;, 
&#39;abcde&#39;, 
&#39;bcde&#39;, 
&#39;cdef&#39;, 
&#39;defg&#39;, 
&#39;defgh&#39; 
); 
$str = &#39;~&#39;.implode(&#39;~&#39;,$array).&#39;~&#39;; 
$word = $_GET[&#39;word&#39;]; //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
Copy after login

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!

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