Complete the code to merge two arrays using the correct function.
<?php $array1 = [1, 2]; $array2 = [3, 4]; $result = [1]($array1, $array2); print_r($result); ?>
The array_merge function merges two or more arrays into one.
Complete the code to combine two arrays into a key-value array.
<?php $keys = ['a', 'b']; $values = [1, 2]; $combined = [1]($keys, $values); print_r($combined); ?>
The array_combine function creates an array by using one array for keys and another for values.
Fix the error in the code to correctly merge arrays with numeric keys.
<?php $array1 = [0 => 'apple', 1 => 'banana']; $array2 = [0 => 'cherry', 1 => 'date']; $merged = [1]($array1, $array2); print_r($merged); ?>
array_merge merges arrays and reindexes numeric keys, so values are appended.
Fill both blanks to create an array of squares for even numbers only.
<?php $numbers = [1, 2, 3, 4, 5]; $squares = [ [1] => [2] for [1] in $numbers if [1] % 2 == 0 ]; print_r($squares); ?>
We use $num as the variable and square it with $num * $num for even numbers.
Fill all three blanks to create an associative array with uppercase keys and values greater than 10.
<?php $data = ['a' => 5, 'b' => 15, 'c' => 20]; $result = [ [1] => [2] for [1], [2] in $data if [3] > 10 ]; print_r($result); ?>
We convert keys to uppercase with strtoupper($key) and keep values where $value > 10.