@Murky , in order to run JavaScript from PHP, you will need to install a corresponding module on the server, for example, v8js .
@ Angus123 , the solution to the “problem for first-graders” will become obvious if we recall that JavaScript is a dynamically typed language, and when you try to perform an action on an object that does not apply to this object, JavaScript will try to bring this object to the appropriate type. In particular, the operation "unary plus" is not applicable to arrays, but it is applicable to numbers. An empty JavaScript array will result in 0, an array with one number will result in this number, an array containing more than one element will result in NaN . Thus, the expression +[] reduced to 0. The logical negation is not applicable to numbers, therefore JavaScript performs the conversion of 0 -> false . Thus, the expression !+[] = true . Similarly !![] = true . Binary addition to Boolean values ​​is not applicable, so they are converted back to numbers !+[]+!![] = true + true = 1 + 1 = 2 . Knowing about such transformations, it is easy to calculate the value of the presented expression.