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 :: php call class dynamically 
Php :: hello world php 
Php :: laravel save photo in both local and database 
Php :: password validation rules laravel 
Php :: how to collapse array in laravel 
Php :: artisan 
Php :: convert laravel hash password online 
Php :: php get max key in associative array 
Php :: stripslashes in php 
Php :: return view in laravel controller 
Php :: laravel observer check if field changed 
Php :: join in laravel 
Php :: wp tax_query in 
Php :: Passing PHP Arrays to JavaScript 
Php :: in array php multiple values 
Php :: laravel truncate string laravel 8 
Php :: php shell_exec with root 
Php :: how to store file in public folder laravel 
Php :: run a php site 
Php :: laravel form put method 
Php :: WooCommerce cart API php 
Php :: next year php string 
Php :: get post index wordpress 
Php :: PHP sqrt() Function 
Php :: laravel create model and migration 
Php :: if browser url is having domain name in it check using php 
Php :: drupal set message 
Php :: laravel distinct not working 
Php :: laravel has one 
Php :: html special characters php 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =