PHP Loops Practice
Use a loop to output a column of numbers from
1 to 100.
Use a loop to output a column of numbers from
100 to 1.
Use a loop to output a column of even numbers
from 1 to 100.
Fill an array with 10 X's using
a loop.
Fill an array with numbers from 1 to 10
using a loop.
Given an array with numbers. Using a loop, output
only those array elements that are greater
than zero and less than 10.
Given an array with numbers. Using a loop, check
if it contains an element with the value 5.
Given an array with numbers. Using a loop, find the sum of the elements of this array.
Given an array with numbers. Using a loop, find the sum of the squares of the elements of this array.
Given an array with numbers. Find the arithmetic mean of its elements (sum of elements divided by the count).
Write a script that will find the factorial of a number. Factorial is the product of all integers less than or equal to the given number.
Given the following array with employees and their salaries:
<?php
$arr = [
'employee1' => 100,
'employee2' => 200,
'employee3' => 300,
'employee4' => 400,
'employee5' => 500,
'employee6' => 600,
'employee7' => 700,
];
?>
Increase each employee's salary by 10%.
Modify the previous task so that
the salary increases only for those employees
whose salary is less than or equal to 400.
Given the following array:
<?php
$arr = [1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10];
?>
Find the sum of the keys of this array and divide it by the sum of the values.
Given the following array:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5];
?>
Write the keys of this array into one array, and the values into another.
Given the following array:
<?php
$arr = [
1 => 125,
2 => 225,
3 => 128,
4 => 356,
5 => 145,
6 => 281,
7 => 452,
];
?>
Write into a new array the elements whose value
starts with the digit 1 or the digit
2. So the resulting array will be
like this:
<?php
[
125,
225,
128,
145,
281,
];
?>