Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php array of objects filter

//Array_filter to filter employee whose salaries are more than 12,000.
$filtered_arr = array_filter($employees_arr,function($employee){ return $employee->get_salary() > 12000;});
 
//Gets the filtered array.
print_r($filtered_arr);
 
 
/*
OUTPUT
Array
(
    [0] => Employee Object   
        (
            [id] => 1        
            [name] => Rachel 
            [salary] => 15000
        )
 
    [1] => Employee Object   
        (
            [id] => 2        
            [name] => Anna   
            [salary] => 14000
        )
 
    [2] => Employee Object
        (
            [id] => 3
            [name] => Robert
            [salary] => 13000
        )
 
)
*/
Comment

PREVIOUS NEXT
Code Example
Php :: string to bool php 
Php :: laravel migration set default value 
Php :: Internal error: xmlSchemaXPathProcessHistory, The state object to be removed is not the first in the list. 
Php :: php auto scoll page with output 
Php :: laravel carbon create date from string 
Php :: php current datettime us time zone 
Php :: header remove php 
Php :: laravel migration add unique column 
Php :: remove html from string php 
Php :: ipn listener paypel php 
Php :: behamin brequest installation on laravel 
Php :: laravel gmail 
Php :: php median 
Php :: foreign key nullable in laravel 
Php :: age php datetime 
Php :: php date format 
Php :: Cannot use object of type stdClass as array 
Php :: php explode 
Php :: take fraction of number in laravel 
Php :: get parameter in php 
Php :: Remove product (item) from WooCommerce checkout page using AJAX 
Php :: php get username from iis 
Php :: laravel naming conventions 
Php :: select sum in laravel 
Php :: laravel checkbox terms and conditions 
Php :: php foreach associative array 
Php :: php variable outside foreach 
Php :: php Call to undefined function mb_convert_case() 
Php :: php serve 
Php :: object to string php 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =