# How To Calculate Fibonacci Extensions using PHP?

, in category: Technical Analysis , 4 months ago

How To Calculate Fibonacci Extensions using PHP?

, 4 months ago

﻿@bridie_mante ﻿

To calculate Fibonacci extensions using PHP, you can follow these steps:

1. Define a function to calculate Fibonacci numbers:
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 ``` ```function fibonacci(\$n) { \$a = 0; \$b = 1; for (\$i = 0; \$i < \$n; \$i++) { \$temp = \$a; \$a = \$b; \$b = \$temp + \$b; } return \$a; } ```

1. Calculate the Fibonacci numbers:
 ```1 2 3 4 5 6 7 8 9 ``` ```\$n = 10; // number of Fibonacci numbers to calculate \$fibonacci_numbers = array(); for (\$i = 0; \$i < \$n; \$i++) { \$fibonacci_numbers[\$i] = fibonacci(\$i); } // Print the Fibonacci numbers print_r(\$fibonacci_numbers); ```

1. Calculate the Fibonacci extensions using the calculated Fibonacci numbers:
 ```1 2 3 4 5 6 7 8 9 ``` ```\$extension_ratio = 1.618; // extension ratio for Fibonacci extensions \$extension_numbers = array(); for (\$i = 0; \$i < \$n; \$i++) { \$extension_numbers[\$i] = \$fibonacci_numbers[\$i] * \$extension_ratio; } // Print the Fibonacci extensions print_r(\$extension_numbers); ```

1. You can now customize the extension ratio and the number of Fibonacci numbers to calculate to get the desired Fibonacci extensions.

Note: This is a basic example of calculating Fibonacci extensions using PHP. You can further optimize and enhance the code based on your requirements.

, 2 months ago

﻿@bridie_mante ﻿

That's a good start! Here is an example with an updated function to calculate Fibonacci extensions using PHP:

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ``` ```function fibonacci(\$n) { \$a = 0; \$b = 1; for (\$i = 0; \$i < \$n; \$i++) { \$temp = \$a; \$a = \$b; \$b = \$temp + \$b; } return \$a; } \$n = 10; // number of Fibonacci numbers to calculate \$fibonacci_numbers = []; \$extension_ratio = 1.618; // extension ratio for Fibonacci extensions for (\$i = 0; \$i < \$n; \$i++) { \$fibonacci_numbers[\$i] = fibonacci(\$i); } // Calculate Fibonacci extensions \$extension_numbers = []; foreach (\$fibonacci_numbers as \$fibonacci_number) { \$extension_numbers[] = \$fibonacci_number * \$extension_ratio; } // Print Fibonacci numbers and extensions echo "Fibonacci Numbers: " . implode(", ", \$fibonacci_numbers) . " "; echo "Fibonacci Extensions: " . implode(", ", \$extension_numbers); ```

You can run this code in a PHP environment to calculate Fibonacci numbers and their extensions using the Fibonacci extension ratio of 1.618. Feel free to customize the extension ratio or the number of Fibonacci numbers calculated as needed.