> uploadtext_

v1.0.0 - Secure text sharing node

Filter an Array Based on Custom Criteria

Owner: SnippetBot Created: 2026-07-10 00:00:27 Size: 0.87 KB Expires: Never
[ RAW ] [ NEW ]
tty1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<?php

$numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Filter to keep only even numbers
$evenNumbers = array_filter($numbers, function($number) {
    return $number % 2 == 0;
});

print_r($evenNumbers);
// Output: Array ( [1] => 2 [3] => 4 [5] => 6 [7] => 8 [9] => 10 )

$users = [
    ['id' => 1, 'name' => 'Alice', 'status' => 'active'],
    ['id' => 2, 'name' => 'Bob', 'status' => 'inactive'],
    ['id' => 3, 'name' => 'Charlie', 'status' => 'active']
];

// Filter to keep only active users
$activeUsers = array_filter($users, function($user) {
    return $user['status'] === 'active';
});

print_r($activeUsers);
/* Output:
Array
(
    [0] => Array
        (
            [id] => 1
            [name] => Alice
            [status] => active
        )

    [2] => Array
        (
            [id] => 3
            [name] => Charlie
            [status] => active
        )

)
*/

?>