0

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));
?>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by twiss
0

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++;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.