
Try this: <?php $arr = array(1,2,4,5,4,5,4,8,9); $count=0; foreach($arr as $val){ if($val==4){ $count=$count+1; }elseif($val==5){ } } print $count; ?> As a basis for your code On Wed, Jul 27, 2011 at 8:20 PM, Peter Karunyu <pkarunyu@gmail.com> wrote:
There is this function called array_walk which allows you to apply your own function to each element of the array and return true or false...
Now, in this user defined function, it would receive a parameter which would be the value of the current array element, check if it is 4 or 5 and return true if so.
However, you might need to write another logic to count the number of 4s returned...
On Wed, Jul 27, 2011 at 7:57 PM, julianne anyim <julianneanyim@gmail.com>wrote:
Hello,
i have an example array below:
e.g $myarray=array(1, 3, 4, 4, 2, 4, 6, 6, 5);
i need to count how many values are equal to 4 and how many are greater than 5.. using php.. such that
IF i have at least two values equal to 4 and atleast one value greater than 5, THEN {execute some code}
your help will be appreciated :)
-- Julie
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- John Wesonga