Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PHP manual says that <code>preg_filter()</code> is identical to <code>preg_replace()</code> except it only returns the matches.</p> <p>So, you can use a combination of <a href="http://php.net/preg_replace" rel="noreferrer"><code>preg_replace</code></a> and <a href="http://php.net/array_diff" rel="noreferrer"><code>array_diff</code></a> to get results like preg_filter in PHP 5.2.x. Do it like this:</p> <pre><code>&lt;?php $subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4'); $pattern = array('/\d/', '/[a-z]/', '/[1a]/'); $replace = array('A:$0', 'B:$0', 'C:$0'); $result = preg_replace($pattern, $replace, $subject); var_dump($result); //take difference of preg_replace result and subject $preg_filter_similar = array_diff($result, $subject); var_dump($preg_filter_similar); ?&gt; </code></pre> <p>This gives the output (with xDebug installed):</p> <pre><code>array 0 =&gt; string 'A:C:1' (length=5) 1 =&gt; string 'B:C:a' (length=5) 2 =&gt; string 'A:2' (length=3) 3 =&gt; string 'B:b' (length=3) 4 =&gt; string 'A:3' (length=3) 5 =&gt; string 'A' (length=1) 6 =&gt; string 'B' (length=1) 7 =&gt; string 'A:4' (length=3) array 0 =&gt; string 'A:C:1' (length=5) 1 =&gt; string 'B:C:a' (length=5) 2 =&gt; string 'A:2' (length=3) 3 =&gt; string 'B:b' (length=3) 4 =&gt; string 'A:3' (length=3) 7 =&gt; string 'A:4' (length=3) </code></pre> <p>Which is same as <a href="http://php.net/manual/en/function.preg-filter.php" rel="noreferrer"><code>preg_filter()</code> output</a>:</p> <pre><code>Array ( [0] =&gt; A:C:1 [1] =&gt; B:C:a [2] =&gt; A:2 [3] =&gt; B:b [4] =&gt; A:3 [7] =&gt; A:4 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload