Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php array_filter

$array = [
    ['name' => 'John', 'age' => 45],
    ['name' => 'Haley', 'age' => 42],
    ['name' => 'Ally', 'age' => 8],
    ['name' => 'Meylyn', 'age' => 5],
    ['name' => 'Nicholas', 'age' => 1],
];


$adults = array_filter($array, function($value) {
    return $value['age'] > 18;
});

foreach ($adults as $adult) {
    echo $adult['name'] . "<br/>";
}
Comment

php array filter


<?php

$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];

var_dump(array_filter($arr, function($k) {
    return $k == 'b';
}, ARRAY_FILTER_USE_KEY));

var_dump(array_filter($arr, function($v, $k) {
    return $k == 'b' || $v == 4;
}, ARRAY_FILTER_USE_BOTH));
?>

Comment

php array_filter

$array = [1, 2, 3, 4, 5];

$filtered = array_filter($array, function($item) {
    return $item != 4; // Return (include) current item if expression is truthy
});

// $filtered = [1, 2, 3, 5]
Comment

php filter array

$numbers = [-2, 4, -6, 8, 10];

function isPositive($number)
{
  return $number > 0;
}

$filteredArray = array_filter($numbers, "isPositive");
Comment

array_filter in php

array_filter( $array, function($value){ return  $value['age']> 18; });
Comment

PREVIOUS NEXT
Code Example
Php :: create function parameters php 
Php :: php get url parameter 
Php :: php color generator 
Php :: get all laravel validation failed messages 
Php :: remove seconds from time php 
Php :: <a href="<?php echo base_url(); ?"somelink</a 
Php :: change key value laravel map collection 
Php :: replace 0 in number to add 234 php 
Php :: how to use a session in blade 
Php :: unlink is a directory laravel 
Php :: ent_quotes in php 
Php :: delete file in php 
Php :: rule In in laravel 
Php :: how to remove duplicate values from an array in php 
Php :: laravel validation unique two columns 
Php :: PHP Forms - Required Fields 
Php :: php foreach index 
Php :: trim array in map php 
Php :: laravel log path 
Php :: magento2 set session timeout cia cli 
Php :: add item to array in php 
Php :: php email attachment and message 
Php :: invalid datetime format laravel 
Php :: limited text show in laravel 
Php :: how to insert multiple selected 
Php :: run xampp application on windows startup 
Php :: php constant 
Php :: Get the post category if you have a custom post_type 
Php :: drupal set message 
Php :: week day php 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =