⊗ppPmRgAF 269 of 447 menu

Filtering an Array Using Regular Expressions in PHP

preg_grep

Given an array of strings:

<?php $array = ['apple', 'banana', 'cherry', 'date', 'fig']; ?>

Filter the array, leaving only the elements starting with the letter 'b'.

Given an array of strings:

<?php $arr = ['error404', 'success', 'warning', 'info', 'error500']; ?>

Filter the array, leaving only the strings containing the word 'error'.

Given an array of strings:

<?php $arr = ['123', '45.6', '78', '9.0', 'text']; ?>

Filter the array, leaving only the strings representing integers.

Given an array of strings:

<?php $arr = [ 'user1@example.com', 'invalid', 'user2@test.org', 'not-email' ]; ?>

Filter the array, leaving only valid email addresses.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline