62 61 58 bytes
This was actually more challenging than I expected! I am quite surprised of how long my code is.
How does it work?
This works by selecting the code to run, from the array.
null) are always truthy, even
new Boolean(false) is truthy!).
But, I need to get it to a numeric value, so, I just use a
!) and convert it to integer (with the
Now, PHP yields the value
Placing the code inside an array, at those indexes, will allow us to select the right code for the desired language.
This can be used as
[JS,PHP][+!], to get the code of the right language.
On previous polyglots, I've used
'\0'=="\0", which is
\0 is parsed as the NULL-byte) and
false in PHP (the
'\0' won't be parsed as the NULL-byte, comparing the literal string
\0 with the NULL-byte).
I'm happy that I've managed to reduce this check to
I'm even more happy about @rckd, which reduced it to the current version!
From there on, it simply
evals the code required.
PHP will execute
echo$argv**.5 (equivalent to
echo sqrt($argv);, square-root the number), receiving the value from the 2nd argument and displays it in the standard output.
alert((_=prompt())*_), which displays the squared number in an
Thank you to @rckd for saving 1 byte, and @user59178 for saving 3 bytes!