I'm trying to get all the characters in that message at positions that are present in the Fibonacci sequence (a sequence formed by the the Fibonacci number sorted in ascending order). Please ignore whitespace characters and use the extended Fibonacci.
Return the obtained characters capitalized and connected by the '-' character.
Example
For message = "The Da Vinci Code is a 2003 mystery-detective novel by Dan Brown",
the output should be
FibonacciSecret(message) = "T-H-H-E-D-V-C-E-M-T".
The first Fibonacci is 0 then the first letter is T
The second Fibonacci is 1 then the second letter is H
The third Fibonacci is 1 then the third letter is H ... and so on.
Thus, the answer should be "T-H-H-E-D-V-C-E-M-T".
Tried Code
<?php
$message = 'The Da Vinci Code is a 2003 mystery-detective novel by Dan Brown';
$str_split = str_split($message);
$x = 0;
$y = 1;
for($i=0;$i<=10;$i++)
{
$z = $x + $y;
$farray[] = $z;
$x=$y;
$y=$z;
}
foreach($farray as $key=>$fvalue){
echo $str_split[$fvalue]."-";
}
?>
Output
h-T-
E_NOTICE : type 8 -- Undefined offset: -1 -- at line 18
-
E_NOTICE : type 8 -- Undefined offset: -1 -- at line 18
-T-h-h-T-
E_NOTICE : type 8 -- Undefined offset: -1 -- at line 18
-
E_NOTICE : type 8 -- Undefined offset: -1 -- at line 18
-T-
Expected Output
the answer should be "T-H-H-E-D-V-C-E-M-T".
Can anyone tell me. Where im going wrong in this one ?