Welcome Guest, Not a member yet? Register   Sign In
array_key_exists()
#1

[eluser]thevenin[/eluser]
My simple code checks if the array contains "hits" column and if not, then creates it for the first time by assigning a value to this column.

However after assigning this value the function array_key_exists() still "tells" in the next loop circulation that the "hits" key doesn't exist. Could you look and comment please?

Code:
foreach($bets as $bet)
{

$hit = 0;

if($bet->homeGoals == $bet->homeScore && $bet->awayGoals == $bet->awayScore):
  $hit = 1;
endif;

if($hit == 1)
{
   if(array_key_exists('hits', $standings)):
     $standings[$bet->username]["hits"] += 1;
     echo '$hit=1, key_exists '.$bet->username.'<br/>';
   else:
     $standings[$bet->username]["hits"] = 1;
     echo '$hit=1, not key_exists '.$bet->username.'<br/>';
   endif;
}
else
{    
   if(!array_key_exists("hits",$standings)):
     $standings[$bet->username]["hits"] = 0;
     echo '$hit=0, not key_exists '.$bet->username.'<br/>';
   endif;
}
}


The result of the code is:

Code:
$hit = 0, not key_exists jack
$hit = 1, not key_exists jack    <-- after this line the array_key_exists("hits",$standings) function should always return TRUE;
$hit = 0, not key_exists masta
$hit = 1, not key_exists skurwix
$hit = 0, not key_exists skurwix
$hit = 0, not key_exists zari
$hit = 0, not key_exists zari
$hit = 0, not key_exists masta
$hit = 0, not key_exists jack
$hit = 1, not key_exists masta
$hit = 0, not key_exists skurwix
$hit = 0, not key_exists zari
$hit = 0, not key_exists jack
$hit = 0, not key_exists skurwix
$hit = 1, not key_exists trolek

After the line I marked above the array_key_exists() function should not return FALSE anymore or maybe I misunderstood something?

Please comment guys.


Messages In This Thread
array_key_exists() - by El Forum - 03-31-2010, 01:12 AM
array_key_exists() - by El Forum - 03-31-2010, 01:26 AM
array_key_exists() - by El Forum - 03-31-2010, 01:28 AM
array_key_exists() - by El Forum - 03-31-2010, 01:30 AM
array_key_exists() - by El Forum - 03-31-2010, 01:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB