it is obvious, Scott: 

>       if ($sumItUp[$name] == "") {

is like to say "if $sumItUp[$name] is an empty string". Means, that if it 
was not assigned, or if it contains any kind of character in it this will 
result to false. 

Try using this: 

if(isset($sumItUp[$name]) and strlen($sumItUp[$name])) {
} 

this will mean: 

if there's such variable defined and the lenght of what it contains is 
bigger than 0 the statement will result TRUE. 

 


Maxim Maletsky 

Founder, Chief Developer
PHPBeginner.com (Where PHP Begins) 

www.PHPBeginner.com
maxim@ phpbeginner.com 

 

 

 


Scott Fletcher writes: 

> Hi! 
> 
>     I'm a little baffled on why the array is not working the way I expect it
> to.  It showed there is something about the array I do not know about.
> Well, it's never too late to learn something new.  So, here's the code and
> see if you can help me out. 
> 
> -- clip -- 
> 
>       $name = "TU4R"; 
> 
>       if ($sumItUp[$name] == "") {
>          $sumItUp[$name] = 0;
>       } else {
> //debug
> echo "**";
>          $number = $sumItUp[$name];
>          $number++;
>          $sumItUp[$name] = $number;
>       }
>       echo $sumItUp[$name]."<br>"; 
> 
> -- clip -- 
> 
>     In this case, the if statement never went into else statement when
> there's a number like 0, 1, 2, etc.  So, what's the heck is happening here?
> When the array, "sumItUp[]" was empty then the number "0" was assigned and
> it work like a charm.  So,  when this code is repeated again, the if
> statement check the array, "sumItUp[]" and found a number, "0" and it is not
> equal to "" as shown in the if statement.  So, therefore the else statement
> should be executed.  But in this case, it never did.  I tested it myself to
> make sure I wasn't missing something by putting in the php codes, "echo
> '**';" and the data, "**" was never spitted out on the webpage.  So, it tell
> me that the else statment was never executed.  So, the problem had to do
> with the data in the array itself.  So, can anyone help me out?  Thanks a
> million!!!!!! 
> 
> Scott 
> 
>  
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php 
> 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to