<?php
function myfunction($a, $b = true)
{
if($a && !$b) {
echo "Hello, World!
";
}
}
$s = array(0 => "my",
1 => "call",
2 => '$function',
3 => ' ',
4 => "function",
5 => '$a',
6 => '$b',
7 => 'a',
8 => 'b',
9 => '');
$a = true;
$b = false;
/* Group A */
$name = $s[?].$s[?].$s[?].$s[?].$s[?].$s[?];
/* Group B */
$name(${$s[?]}, ${$s[?]});
?>
The question is the following: Each ? in the above script represents an integer index against the $s array. In order to display the Hello, World! string when executed, what must the missing integer indexes be?
This ain't for a homework/exam, it's from an eBook I am reading, but I can't seem to understand what is happening exactly.
The given answers are the following:
1: Group A: 4,3,0,4,9,9 Group B: 7,8
2: Group A: 1,3,0,4,9,9 Group B: 7,6
3: Group A: 1,3,2,3,0,4 Group B: 5,8
4: Group A: 0,4,9,9,9,9 Group B: 7,8
5: Group A: 4,3,0,4,9,9 Group B: 7,8
The correct answer is 4, but I don't understand what example is happening in the code. I have learned that functions in PHP can be called dynamically, but I don't understand how it's done in this example. I would appreciate if anyone can explain to me step by step how we get the answer to this example.