3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Задача 18: Дадени са два едномерни масива с естествени числа. Да се състави програма, която сравнява всички числа с еднакви индекси от двата масива и записва в трети масив, по-голямото от двете числа. Да се изведе съдържанието и на трите масива Пример: 18,19,32,1,3, 4, 5, 6, 7, 8 1, 2, 3,4,5,16,17,18,27,11 Изход: 18,19,32 ,4,5,16,17,18,27,11 */ $arr1 = [18,19,32,1,3, 4, 5, 6, 7, 8]; $arr2 = [18,19,32,4,5,16,17,18,27,11]; $result = []; foreach ($arr1 as $key => $value) { $result[$key] = (isset($arr2[$key]) && $arr1[$key] > $arr2[$key]) ? $arr1[$key] : $arr2[$key]; } print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 18 [1] => 19 [2] => 32 [3] => 4 [4] => 5 [5] => 16 [6] => 17 [7] => 18 [8] => 27 [9] => 11 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.72 ms | 401 KiB | 8 Q