PHP Loops Practice

Задание 1

Use a loop to output a column of numbers from 1 to 100.

Задание 2

Use a loop to output a column of numbers from 100 to 1.

Задание 3

Use a loop to output a column of even numbers from 1 to 100.

Задание 4

Fill an array with 10 X's using a loop.

Задание 5

Fill an array with numbers from 1 to 10 using a loop.

Задание 6

Given an array with numbers. Using a loop, output only those array elements that are greater than zero and less than 10.

Задание 7

Given an array with numbers. Using a loop, check if it contains an element with the value 5.

Задание 8

Given an array with numbers. Using a loop, find the sum of the elements of this array.

Задание 9

Given an array with numbers. Using a loop, find the sum of the squares of the elements of this array.

Задание 10

Given an array with numbers. Find the arithmetic mean of its elements (sum of elements divided by the count).

Задание 11

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.

Задание 12

Given the following array with employees and their salaries:

php<?php
  $arr = [
    'employee1' => 100,
    'employee2' => 200,
    'employee3' => 300,
    'employee4' => 400,
    'employee5' => 500,
    'employee6' => 600,
    'employee7' => 700,
  ];
?>

Increase each employee's salary by 10%.

Задание 13

Modify the previous task so that the salary increases only for those employees whose salary is less than or equal to 400.

Задание 14

Given the following array:

php<?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.

Задание 15

Given the following array:

php<?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.

Задание 16

Given the following array:

php<?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<?php
  [
    125,
    225,
    128,
    145,
    281,
  ];
?>