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 :: withdefault laravel 
Php :: request update password laravel 
Php :: calculate percentage of amount in php 
Php :: php remove non utf-8 characters 
Php :: where with and and or in a laravel 
Php :: php html template if conditions 
Php :: update profile method in laravel 
Php :: pass image path in laravel blade 
Php :: laravel resource set status code 
Php :: php redirect with query string 
Php :: define return type for php function string or boolean 
Php :: increase php_values 
Php :: Laravel: Set timestamp column to current timestamp 
Php :: php pdf 
Php :: how to include file in php 
Php :: Eloquent where date methods 
Php :: multiple submit button in php 
Php :: laravel carbon time format 
Php :: wordpress get plugin list 
Php :: laravel enable mysql logging 
Php :: 413 error laravel 
Php :: install laravel on windows 
Php :: remove last comma from string php foreach 
Php :: route laravel Target class [AuthController] does not exist 
Php :: Genrate Random number in php 
Php :: php input time validation 
Php :: apache using wrong php version 
Php :: setcookie in php 
Php :: eager load relationships by default in the model laravel 
Php :: how to insert data in table and fetch in wordpress 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =