Re: array_filter with two conditions

Postiljon Petskin <[email protected]> Sat, 22 Apr 2023 08:47:37 -0700 (PDT)
Newsgroups comp.lang.php
Message-ID <[email protected]>
On Friday, January 5, 2018 at 2:11:50 AM UTC+2, jans wrote:
> I am having trouble debugging this? I can't get it to print out the value if it is even or the word "odd" if it is odd? The initial funcitons work but I don't know how to use the array_filter with two conditions? thanks, 
> function odd($var) 
> { 
> // returns whether the input integer is odd 
> return($var & 1); 
> } 
> 
> function even($var) 
> { 
> // returns whether the input integer is even 
> return(!($var & 1)); 
> } 
> 
> $arr = array(1,2,6,7,9,4,10,11,12,3,13,24); 
> $keys = array_keys($arr); 
> 
> for ($counter = 0, $length = count($arr);$counter < $length; $counter++) 
> { 
> $key = $keys[$counter]; 
> $value = $array[$key]; 
> if ($arr_filter($arr,'even')==1){ 
> print_r($array[$key];); 
> }elseif($arr_filter($arr,'odd')==1) 
> { 
> print_r('odd'); 
> } 
> }

You agree, that You are the most unoriginal person in the history of the universe ?