for example can how can I properly write,
$a = 'cat-dog';
echo ((strpos($a, '-') !== false));
// and get true on 开发者_JAVA技巧screen.
Without having to use a separate variable to store the value.
Thank you so much!You could use the function var_dump();
instead of echo
. Have a look at the manual.
For example:
$a = 'cat-dog';
var_dump(strpos($a, '-') !== false);
//Would output: bool(true)
Use the ternary operator:
echo ((strpos($a, '-') !== false) ? "true" : "false");
$a = 'cat-dog';
echo (strpos($a, '-') !== false)
? "true"
: "false";
Can't you just cast the result to string with (string)($AnyResult)?
instead of stacking operators and using ternary operator you have also possibility to write readable and maintainable code
$a = 'cat-dog';
$pos = strpos($a, '-');
if ($pos !== false) {
echo "TRUE";
}
I see no rocket science in it though. just regular PHP operators, donno what made it trouble for you.
精彩评论