PHP: issue with comparing variables -
I have two PHP variables that can either be empty (i.e. I want to do a simple check here and say if a variable is not empty and is equal to the second check the checkbox, but it does not work. Someone here can show me what I am doing (checkbox should be checked in the example below)? My problem is that the checkbox is always checked, even if the variable does not match. Example: Many thanks for any help with this, Tim. Then int gives the function, but what kind of int? According to the manual: returns & lt; 0 if str1 is less than str2; & Gt; 0 If str1 is larger than str2, and 0 if they are equal. In other words: if both the strings are the same, then Believes the fact that 2 strings do not match. Of course, you only want to see the ckeckbox when two string not match: It should do, of course, it still depends on your calling function so that these stars can be considered equal. It's not really adding, though, and might just be easy to write: Note , as you already know, is built on PHP C, And so there is a lot of C-like value = "" ) Or the name in the format Last, with a space between the first one comma and the last and first names (such as the mouse, Mickey)
$ poc1 = "Mouse, Mikey"; // $ poc2 = "Hard-coded for testing mouse, Mikey"; // Hard-coded for testing & lt; Input type = "checkbox" id = "check2" name = "Copy_POC" & lt ;? Php if (($ poc2! = "") & Amp; amp; & amp; amp; & amp; amp; & amp; amp; amp; amp; amp; amp; amp; amp; Amp; amp; amp; Poc1))) {resonant "check"; }? & Gt; / & Gt;
strcmp requires the signature of the function, and its Return value:
strcmp returns
0 , which is
false The evaluation for what you should have written is:
strcmp ($ str1, $ str2)! == 0
if ($ str1! = '' & Amp; amp; strcmp ($ str1, $ str2) === 0) {// checked}
if ($ str1 & $ str1 === $ str2) / / an empty string falsy + type & Amp; Check the value on 2 strings using the Operator
str * function whenever you see functions like
strcmp and
strstr , see its return value. Like the
string.h function, it is often either an indicator (the part of the string where estering is found, like
strstr ) , Or an integer (index / offset string) ...
Comments
Post a Comment