-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-two.php
More file actions
46 lines (35 loc) · 753 Bytes
/
problem-two.php
File metadata and controls
46 lines (35 loc) · 753 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
*
* Project Euler #2 - PHP
*
*/
define ("MAX_VALUE", 35);
$fibonacci_array = [1,2];
$even_sum_array = [];
$sum = 0;
$even_sum = 0;
for ( $i = 0; $i < 50; $i++ ) {
$sum = $fibonacci_array[$i] + $fibonacci_array[$i+1];
array_push( $fibonacci_array, $sum );
if ( ( $fibonacci_array[$i]%2 ) == 0 ) {
array_push( $even_sum_array, $fibonacci_array[$i] );
};
};
for ($i = 0; $i < count($even_sum_array); $i++) {
if ( $even_sum_array[$i] < MAX_VALUE ) {
$even_sum += $even_sum_array[$i];
};
};
?>
<h1><?php echo $even_sum; ?></h1>
<?php
echo 'Fibonacci Array';
echo '<pre>';
print_r( $fibonacci_array);
echo '</pre>';
echo 'Even Sum Array';
echo '<pre>';
print_r( $even_sum_array );
echo '</pre>';
?>