Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,955 questions

51,897 answers

573 users

How to check if all array item is more than N with array_reduce() in PHP

2 Answers

0 votes
$b = array_reduce([11, 13, 300, 98, 506, 17], function($yesno, $item){
        echo $yesno . ' : ' . $item . "<br />";
        return $yesno && $item > 10;
}, true); 

if ($b)
    echo "yes";
else
    echo "no";
 
  
/*
run:
   
1 : 11
1 : 13
1 : 300
1 : 98
1 : 506
1 : 17
yes 
   
*/

 



answered Oct 6, 2017 by avibootz
0 votes
$array = [11, 13, 300, 2, 506, 17];

$b = array_reduce($array, function($yesno, $item){
        echo $yesno . ' : ' . $item . "<br />";
        return $yesno && $item > 10;
}, true); 

if ($b)
    echo "yes";
else
    echo "no";
 
  
/*
run:
   
1 : 11
1 : 13
1 : 300
1 : 2
: 506
: 17
no 
   
*/

 



answered Oct 6, 2017 by avibootz

Related questions

...