-2

I want to filter out the array with status=paid, is there any builtin PHP function for this?

Array
(

[0] => Array
        (

            [id] => 140
            [status] => paid

        )

[1] => Array
        (

            [id] => 140
            [status] => new

        )
[2] => Array
        (

            [id] => 140
            [status] => new

        )
)
Pradeep
  • 9,667
  • 13
  • 27
  • 34
Musawar
  • 93
  • 3
  • 10

3 Answers3

5

You can try this-

$musawar = array_filter($arr, function ($var) {
    return ($var['status'] == 'paid');
});

Another way is -

function my_filter($elt) {
    return $elt['status'] == 'paid';
}
Rashed
  • 2,349
  • 11
  • 26
1
$filtered = array_filter($raw, function($element) {
   return $element['status'] === 'paid';
});
0

Use a function like this :

array_filter($yourArray, "statusPaid")

Then define the callback function statusPaid(), to check [status]. It has only to return a check on ['status'] == 'paid' for each element of your array

Doc here