From 3cd701ff39e73e59863594bcc7fc65a32250b189 Mon Sep 17 00:00:00 2001 From: Igor Simdyanov Date: Mon, 18 Apr 2022 08:53:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BB=D0=B0=D0=B2=D0=B0=2011:=20=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=BD=D0=BE=D0=B2=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arrays/array.php | 5 +++++ arrays/array_cast.php | 6 ++++++ arrays/array_eq.php | 23 +++++++++++++++++++++++ arrays/array_eqvl.php | 15 +++++++++++++++ arrays/array_key_exists.php | 5 +++++ arrays/array_merge.php | 7 +++++++ arrays/array_multi.php | 9 +++++++++ arrays/array_search.php | 5 +++++ arrays/array_unset.php | 10 ++++++++++ arrays/assoc.php | 5 +++++ arrays/assoc_add.php | 6 ++++++ arrays/assoc_get.php | 5 +++++ arrays/assoc_same_keys.php | 5 +++++ arrays/brackets.php | 5 +++++ arrays/curly_brackets.php | 4 ++++ arrays/for.php | 5 +++++ arrays/foreach.php | 9 +++++++++ arrays/foreach_alter.php | 9 +++++++++ arrays/foreach_multi.php | 14 ++++++++++++++ arrays/index.php | 5 +++++ arrays/index_auto.php | 7 +++++++ arrays/indexes.php | 5 +++++ arrays/indexes_default.php | 5 +++++ arrays/interpolate.php | 4 ++++ arrays/interpolate_assoc.php | 4 ++++ arrays/interpolate_multi.php | 6 ++++++ arrays/is_array.php | 14 ++++++++++++++ arrays/isset.php | 10 ++++++++++ arrays/keys_types_ignore.php | 15 +++++++++++++++ arrays/list.php | 6 ++++++ arrays/list_assoc.php | 6 ++++++ arrays/list_incomplete.php | 4 ++++ arrays/plus.php | 7 +++++++ arrays/plus_alter.php | 7 +++++++ arrays/print_r.php | 5 +++++ arrays/search_element.php | 7 +++++++ arrays/square.php | 7 +++++++ arrays/strict.php | 7 +++++++ arrays/unset.php | 10 ++++++++++ arrays/vars_exchange.php | 13 +++++++++++++ 40 files changed, 306 insertions(+) create mode 100644 arrays/array.php create mode 100644 arrays/array_cast.php create mode 100644 arrays/array_eq.php create mode 100644 arrays/array_eqvl.php create mode 100644 arrays/array_key_exists.php create mode 100644 arrays/array_merge.php create mode 100644 arrays/array_multi.php create mode 100644 arrays/array_search.php create mode 100644 arrays/array_unset.php create mode 100644 arrays/assoc.php create mode 100644 arrays/assoc_add.php create mode 100644 arrays/assoc_get.php create mode 100644 arrays/assoc_same_keys.php create mode 100644 arrays/brackets.php create mode 100644 arrays/curly_brackets.php create mode 100644 arrays/for.php create mode 100644 arrays/foreach.php create mode 100644 arrays/foreach_alter.php create mode 100644 arrays/foreach_multi.php create mode 100644 arrays/index.php create mode 100644 arrays/index_auto.php create mode 100644 arrays/indexes.php create mode 100644 arrays/indexes_default.php create mode 100644 arrays/interpolate.php create mode 100644 arrays/interpolate_assoc.php create mode 100644 arrays/interpolate_multi.php create mode 100644 arrays/is_array.php create mode 100644 arrays/isset.php create mode 100644 arrays/keys_types_ignore.php create mode 100644 arrays/list.php create mode 100644 arrays/list_assoc.php create mode 100644 arrays/list_incomplete.php create mode 100644 arrays/plus.php create mode 100644 arrays/plus_alter.php create mode 100644 arrays/print_r.php create mode 100644 arrays/search_element.php create mode 100644 arrays/square.php create mode 100644 arrays/strict.php create mode 100644 arrays/unset.php create mode 100644 arrays/vars_exchange.php diff --git a/arrays/array.php b/arrays/array.php new file mode 100644 index 0000000..1a59769 --- /dev/null +++ b/arrays/array.php @@ -0,0 +1,5 @@ +'; +print_r($arr); +echo ''; diff --git a/arrays/array_eq.php b/arrays/array_eq.php new file mode 100644 index 0000000..551ded0 --- /dev/null +++ b/arrays/array_eq.php @@ -0,0 +1,23 @@ +'; +} else { + echo 'Массивы не равны
'; +} + +if ($ar1 == $ar3) { + echo 'Массивы равны
'; +} else { + echo 'Массивы не равны
'; +} + +if ($ar1 == $ar4) { + echo 'Массивы равны
'; +} else { + echo 'Массивы не равны
'; +} diff --git a/arrays/array_eqvl.php b/arrays/array_eqvl.php new file mode 100644 index 0000000..0c7eb5f --- /dev/null +++ b/arrays/array_eqvl.php @@ -0,0 +1,15 @@ + 1, 2 => 2]; +$snd = [1 => 1, 2 => '2']; + +if ($fst == $snd) { + echo 'Массивы равны
'; +} else { + echo 'Массивы не равны
'; +} + +if ($fst === $snd) { + echo 'Массивы эквивалентны
'; +} else { + echo 'Массивы не эквивалентны
'; +} diff --git a/arrays/array_key_exists.php b/arrays/array_key_exists.php new file mode 100644 index 0000000..c56de23 --- /dev/null +++ b/arrays/array_key_exists.php @@ -0,0 +1,5 @@ + 1, 'second_numb' => 2]; +if (array_key_exists('first_numb', $arr)) { + echo 'ОК'; +} diff --git a/arrays/array_merge.php b/arrays/array_merge.php new file mode 100644 index 0000000..80c1842 --- /dev/null +++ b/arrays/array_merge.php @@ -0,0 +1,7 @@ +'; +print_r($sum); +echo ''; diff --git a/arrays/array_multi.php b/arrays/array_multi.php new file mode 100644 index 0000000..2228699 --- /dev/null +++ b/arrays/array_multi.php @@ -0,0 +1,9 @@ + ['Лайнер', 'Яхта', 'Паром'], + 'Военные корабли' => ['Авианосец', 'Линкор', 'Эсминец'], + 'Грузовые корабли' => ['Сормовский', 'Волго-Дон', 'Окский'] +]; +echo '
';
+print_r($ships);
+echo '
'; diff --git a/arrays/array_search.php b/arrays/array_search.php new file mode 100644 index 0000000..4e709fa --- /dev/null +++ b/arrays/array_search.php @@ -0,0 +1,5 @@ + 'blue', 1 => 'red', 2 => 'green', 3 => 'red']; + +$key = array_search('green', $array); // $key = 2; +$key = array_search('red', $array); // $key = 1; diff --git a/arrays/array_unset.php b/arrays/array_unset.php new file mode 100644 index 0000000..8af96da --- /dev/null +++ b/arrays/array_unset.php @@ -0,0 +1,10 @@ +'; +print_r($arr); // PHP Warning: Undefined variable $arr +echo ''; diff --git a/arrays/assoc.php b/arrays/assoc.php new file mode 100644 index 0000000..fc8f72e --- /dev/null +++ b/arrays/assoc.php @@ -0,0 +1,5 @@ + '1', 'two' => '2']; +echo '
';
+print_r($arr);
+echo '
'; diff --git a/arrays/assoc_add.php b/arrays/assoc_add.php new file mode 100644 index 0000000..91c2488 --- /dev/null +++ b/arrays/assoc_add.php @@ -0,0 +1,6 @@ +'; +print_r($arr); +echo ''; diff --git a/arrays/assoc_get.php b/arrays/assoc_get.php new file mode 100644 index 0000000..ddb6bbb --- /dev/null +++ b/arrays/assoc_get.php @@ -0,0 +1,5 @@ + '1', 'two' => '2']; +echo $arr['one']; // 1 +echo '
'; // Перевод строки +echo $arr['two']; // 2 diff --git a/arrays/assoc_same_keys.php b/arrays/assoc_same_keys.php new file mode 100644 index 0000000..60ea843 --- /dev/null +++ b/arrays/assoc_same_keys.php @@ -0,0 +1,5 @@ + '1', 'two' => '2', 'two' => '3']; +echo $arr['one']; // 1 +echo '
'; // Перевод строки +echo $arr['two']; // 3 diff --git a/arrays/brackets.php b/arrays/brackets.php new file mode 100644 index 0000000..1e38c9f --- /dev/null +++ b/arrays/brackets.php @@ -0,0 +1,5 @@ + '1', + 'second' => '2', + 'third' => '3' +]; +foreach ($arr as $index => $val) { + echo "$index = $val
"; +} diff --git a/arrays/foreach_alter.php b/arrays/foreach_alter.php new file mode 100644 index 0000000..c494857 --- /dev/null +++ b/arrays/foreach_alter.php @@ -0,0 +1,9 @@ + '1', + 'second' => '2', + 'third' => '3' +]; +foreach ($number as $val) { + echo $val; // выведет 123 +} diff --git a/arrays/foreach_multi.php b/arrays/foreach_multi.php new file mode 100644 index 0000000..55c7632 --- /dev/null +++ b/arrays/foreach_multi.php @@ -0,0 +1,14 @@ + ['Лайнер','Яхта','Паром'], + 'Военные корабли' => ['Авианосец','Линкор','Эсминец'], + 'Грузовые корабли' => ['Сормовский','Волго-Дон','Окский'] +]; +foreach ($ship as $key => $type) { + // Вывод значений основных массивов + echo "$key
"; + foreach ($type as $ship) { + // Вывод значений для каждого из массивов + echo "
  • $ship
  • "; + } +} diff --git a/arrays/index.php b/arrays/index.php new file mode 100644 index 0000000..53a24a4 --- /dev/null +++ b/arrays/index.php @@ -0,0 +1,5 @@ + 'Hello, ', 'world', '!']; +echo '
    ';
    +print_r($arr);
    +echo '
    '; diff --git a/arrays/index_auto.php b/arrays/index_auto.php new file mode 100644 index 0000000..ca6ebfa --- /dev/null +++ b/arrays/index_auto.php @@ -0,0 +1,7 @@ +'; +print_r($arr); +echo ''; diff --git a/arrays/indexes.php b/arrays/indexes.php new file mode 100644 index 0000000..41f6abd --- /dev/null +++ b/arrays/indexes.php @@ -0,0 +1,5 @@ + 'Hello, ', 9 => 'world', 8 => '!']; +echo '
    ';
    +print_r($arr);
    +echo '
    '; diff --git a/arrays/indexes_default.php b/arrays/indexes_default.php new file mode 100644 index 0000000..abd3a89 --- /dev/null +++ b/arrays/indexes_default.php @@ -0,0 +1,5 @@ + 'Hello, ', 9 => 'world', '!']; +echo '
    ';
    +print_r($arr);
    +echo '
    '; diff --git a/arrays/interpolate.php b/arrays/interpolate.php new file mode 100644 index 0000000..4cdd1f6 --- /dev/null +++ b/arrays/interpolate.php @@ -0,0 +1,4 @@ +"; +// Событие произошло 14 дней назад +echo "Событие произошло {$arr[0][0]} дней назад
    "; +// Событие произошло 14 дней назад diff --git a/arrays/is_array.php b/arrays/is_array.php new file mode 100644 index 0000000..9561c28 --- /dev/null +++ b/arrays/is_array.php @@ -0,0 +1,14 @@ +'; +} else { + echo 'Это не массив
    '; +} + +if (is_array($arr[0])) { + echo 'Это массив
    '; +} else { + echo 'Это не массив
    '; +} diff --git a/arrays/isset.php b/arrays/isset.php new file mode 100644 index 0000000..370afa4 --- /dev/null +++ b/arrays/isset.php @@ -0,0 +1,10 @@ + 1, 2, 3]; + +for ($i = 0; $i < 10; $i++) { + if (isset($arr[$i])) { + echo "Элемент \$arr[$i] существует
    "; + } else { + echo "Элемент \$arr[$i] не существует
    "; + } +} diff --git a/arrays/keys_types_ignore.php b/arrays/keys_types_ignore.php new file mode 100644 index 0000000..1dd0e8c --- /dev/null +++ b/arrays/keys_types_ignore.php @@ -0,0 +1,15 @@ + 1, 2 => 2]; +$snd = [1 => 1, '2' => 2]; + +if ($fst == $snd) { + echo 'Массивы равны
    '; +} else { + echo 'Массивы не равны
    '; +} + +if ($fst === $snd) { + echo 'Массивы эквивалентны
    '; +} else { + echo 'Массивы не эквивалентны
    '; +} diff --git a/arrays/list.php b/arrays/list.php new file mode 100644 index 0000000..674a5df --- /dev/null +++ b/arrays/list.php @@ -0,0 +1,6 @@ + 1, 'two' => 2, 'three' => 3]; +list($one, $two, $three) = $arr; +echo $one; // Notice: Undefined offset +echo $two; // Notice: Undefined offset +echo $three; // Notice: Undefined offset diff --git a/arrays/list_incomplete.php b/arrays/list_incomplete.php new file mode 100644 index 0000000..bbb60d3 --- /dev/null +++ b/arrays/list_incomplete.php @@ -0,0 +1,4 @@ + 'one', 2 => 'two']; +$snd = [3 => 'three', 4 => 'four']; +$sum = $fst + $snd; +echo '
    ';
    +print_r($sum);
    +echo '
    '; diff --git a/arrays/plus_alter.php b/arrays/plus_alter.php new file mode 100644 index 0000000..c7d5854 --- /dev/null +++ b/arrays/plus_alter.php @@ -0,0 +1,7 @@ +'; +print_r($sum); +echo ''; diff --git a/arrays/print_r.php b/arrays/print_r.php new file mode 100644 index 0000000..2988c88 --- /dev/null +++ b/arrays/print_r.php @@ -0,0 +1,5 @@ +'; +print_r($arr); +echo ''; diff --git a/arrays/search_element.php b/arrays/search_element.php new file mode 100644 index 0000000..786cbd4 --- /dev/null +++ b/arrays/search_element.php @@ -0,0 +1,7 @@ +'; +print_r($arr); +echo ''; diff --git a/arrays/strict.php b/arrays/strict.php new file mode 100644 index 0000000..01999bd --- /dev/null +++ b/arrays/strict.php @@ -0,0 +1,7 @@ +'; +print_r($arr); +echo ''; diff --git a/arrays/vars_exchange.php b/arrays/vars_exchange.php new file mode 100644 index 0000000..7f6aa90 --- /dev/null +++ b/arrays/vars_exchange.php @@ -0,0 +1,13 @@ +"; +echo "x = $x
    "; // 4 +echo "y = $y
    "; // 5 + +list($y, $x) = [$x, $y]; + +echo "после:
    "; +echo "x = $x
    "; // 5 +echo "y = $y
    "; // 4