Answer the question
In order to leave comments, you need to log in
A curious question from a test task?
Hello habravians. They sent me test tasks from one office, and among the questions there is this:
Given the code
$x = ....;
if ($x == 1 && $x==2 && $x==3){
echo("ok");
}
What needs to be substituted in $x so that “ok” is displayed in the console.
I went through all the options in my head, but I never figured out how one variable can go through three comparisons at once with different values. Perhaps this question is about knowing some PHP features, but from my point of view, this task does not have a solution.
So the question is: does this problem have a solution?
Answer the question
In order to leave comments, you need to log in
$x = print("ok");
if ($x == 1 && $x==2 && $x==3){
echo("ok");
}
I do not understand the purpose for which such tasks are given (yes, I do not remember by heart the rules for casting types). Are they looking for people who will code for them in this style? Are they looking for lovers of memorizing documentation?
I do not know php at all, but at the level of intuition: it is necessary that in $X there would be an int type. then when comparing type int with any number, true will be returned
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question