eval.in

Paste #70406

PHP — PHP 5.5.1, pasted 5 years ago (json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
$myArray = array('item1', 'item2hidden', 'item3', 'item4', 'item5hidden');

$arr1 = array_filter($myArray, function($v) { return strpos($v, 'hidden') === false; });
$arr2 = array_filter($myArray, function($v) { return strpos($v, 'hidden') !== false; });
// or 
$arr2 = array_diff($myArray, $arr1);

print_r($arr1);
print_r($arr2);

Program Output

Array
(
    [0] => item1
    [2] => item3
    [3] => item4
)
Array
(
    [1] => item2hidden
    [4] => item5hidden
)

OK (0.008 sec real, 0.007 sec wall, 14 MB, 92 syscalls)

Fork