0

I found the following code snippet on the internet. I've tested the code and it is valid, it returns 7 and no errors. At the end of the snippet there is a PHP expression that I can't understand.

<?php
$array = ['name' => "Manuel", "age" => 39];

$array = $array + $array;
$array = array_flip($array);
$array = array_reverse($array);
$array = array_flip($array);
$array = array_map('strlen', $array);
${"result?"} = array_sum($array);

echo ${"result?"};

I've played with the code, did some research, even discussed with a few friends offline. Maybe there is something I'm missing, but I can't figure out how does PHP interpret ${"result?"}. I guess the thing that throws me off the most is the ?.

Radu
  • 1,159
  • 3
  • 22
  • 40
  • 3
    https://www.php.net/manual/en/language.variables.variable.php might help – nologin Apr 14 '19 at 09:41
  • @nologin can you be more explicit? – Radu Apr 14 '19 at 09:48
  • 2
    The string "result?" is interpreted as a variable name using the brackets "{}" preceded by the $. The point of the "?" is to address the result as a question, "how much it is?" but this is just an opinion. – Adrian Caragea Apr 14 '19 at 09:48
  • This question is to broad IMO - and what did you found already? Have you done any research? – Koen Hollander Apr 14 '19 at 09:51
  • @KoenHollander yes I did, I have played with the code and did some research in the documentation, even asked a few friends. I see your point about the title being too broad - I'm open to suggestions. – Radu Apr 14 '19 at 09:58
  • 1
    And this is __not__ variable variables. – u_mulder Apr 14 '19 at 10:08
  • why can't you just call it `$result` and then `"$result"`? there's even no point in using `"..."`. – Martin Zeitler Apr 14 '19 at 16:56

0 Answers0