How can I return the returned function boolean?I mean this in another programming language.
boolean
return true; // return false
The question is not entirely clear, because you did not ask for something that you have already decided.
A function in PHP can be performed as follows.
function check($int) { if ($int == 3) { return true; } else { return false; } } if (check(3)) echo "Returned true!";
Incredibly enough
return true;
eg.
function testIfABC($x) { if ($x === 'ABC') { return true; } return false; }
although it would be easier to write as:
function testIfABC($x) { return ($x === 'ABC'); }
which will still return a boolean
<?php function doSomething() { return true; }
, , :
function check($var, $length) { return (strlen($var)<=$length) && (isset($var)); } ?>
:
return ($data != "expected") or ($param == 17);
PHP 5.5 boolval:
boolval
(PHP 5 >= 5.5.0, PHP 7) boolval —
return boolval( $result );
boolean. , , :
To explicitly convert a value to boolean, use the (bool)or drives (boolean). However, in most cases, casting is not necessary, since the value will be automatically converted if the operator, function or control structure requires a logical argument
(bool)
(boolean)
return (bool) $result; return (boolean) $result;
I understand the question, since in Visual C # you can define a function to return only bool. This does not apply to PHP. You can simply use the blabla ($ val) {return ($ val == "yes"? True: false) function; }. No support for "public bool ($ value) {return true; // false}"
Source: https://habr.com/ru/post/1790694/More articles:Selecting a first-level text element ".text ()" without selecting child elements - jqueryGPS service in Android - androidHow to disable caching in OpenJPA 2.0.1 (change: problems with BoneCP) - javaHow to clear the user settings file during deletion? - .netorg.jdom.input.JDOMParseException: content not allowed in trailing section - javadoes anyone know about the push / commet server method in gwt - pushValidateInput (false), но теперь, как сохранить мой HTML-вход чистым? - c#Can someone tell me what dataviz is? - chartsDownload a large sample of application data - androidcan we make websphere portal CSA and spring MVC3 work together? - websphere-portalAll Articles