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 :: laravel 6 use username on url 
Php :: chunk_split (PHP 4, PHP 5, PHP 7, PHP 8) chunk_split — Split a string into smaller chunks 
Php :: laravel "query()-find" 
Php :: laravel Pushing To Array Session Values 
Php :: if ip is 
Php :: laravel api error return homepage 
Php :: laravel follow and unfollow relationship 
Php :: install php-mysql 
Php :: laravel crud example 
Php :: show date php by letters 
Php :: laravel error 422 unprocessable entity 
Php :: infinite loop php 
Php :: isset php 
Php :: Make livewire component 
Php :: doctrine where 
Php :: parameter to laravel seeder 
Php :: laravel, if -get() array is not emtpy 
Php :: laravel permissions package 
Php :: php form validation 
Php :: if one condition 
Php :: php mysql 
Php :: extract in php useful 
Php :: join multiple query in laravel 
Php :: deleting a database in phpmyadmin 
Php :: php mail merge docx document 
Php :: pegar porcentagem de um valor php 
Php :: php remove utf non breaking space 
Php :: slim disable display error details 
Php :: Woofood Availability checker 
Php :: ob_start store variable in php 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =