Hi All,

I have a multidimentional array. What I want to do is increment $a each time i find an array element with a certain value.

my array comes from a mysql query. So lets say sex can be male or female, how can i get it to only increment where value = male.

im lost in the below code

while($result = mysql_fetch_array($query)) 
{     
	$resultSet[] = $result; 
} 
//echo $_SESSION['mainquery'];
//echo $data = $_SESSION['mainquery'];
//echo "<br>";
//if ($data == ''){
//	
//	$SQL = "SELECT * FROM accounts WHERE date(timestamp_dtm) = '2011-05-17' and status IN ('COMPLETED','COMPLETED-TRANSFERRED')";
//	$_SESSION['mainquery'] = mysql_query($SQL);
//	echo $SQL;
//} else if ($data != ''){
//	
//	echo "i already had a value";
//}
function search($array, $key, $value)
{
    $results = array();

    if (is_array($array))
    {
        if ($array[$key] == $value)
            $results[] = $array;

        foreach ($array as $subarray)
            $results = array_merge($results, search($subarray, $key, $value));
    }

    return $results;
}
//$hasRed = (isset($array['status'] && in_array('completed', $array['status']));

//print_r(array_values($resultSet));
?>

As I understand it, you want to count the amount of males? The easiest way (I think) is something like this:

$males = 0;
while($result = mysql_fetch_array($query))
{
	$resultSet[] = $result;
	if($result['sex'] == 'male') $males++;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.