Complete the code to add a string number and an integer.
<?php $result = '5' [1] 3; echo $result; ?>
Using + causes PHP to convert the string '5' to the number 5 and then add 3, resulting in 8.
Complete the code to concatenate a string and a number.
<?php $result = 'Value: ' [1] 10; echo $result; ?>
The dot operator . concatenates strings in PHP, so 'Value: ' and 10 become 'Value: 10'.
Fix the error in the code to correctly multiply a string number by an integer.
<?php $result = '4' [1] 2; echo $result; ?>
The multiplication operator * converts the string '4' to number 4 and multiplies by 2, resulting in 8.
Fill both blanks to create an array where keys are string lengths and values are the strings themselves, only for strings longer than 3 characters.
<?php $words = ['apple', 'cat', 'banana', 'dog']; $result = array_combine(array_map('strlen', array_filter($words, function($word) { return strlen($word) [1] 3; })), array_filter($words, function($word) { return strlen($word) [2] 3; })); print_r($result); ?>
The condition strlen($word) > 3 filters words longer than 3 characters. array_map('strlen', filtered_words) gets lengths as keys for the filtered strings.
Fill both blanks to create a dictionary with uppercase keys, original values, and only include values greater than 10.
<?php $data = ['a' => 5, 'b' => 15, 'c' => 20]; $result = array_filter(array_combine(array_map('[1]', array_keys($data)), $data), function($value) { return $value [2] 10; }); print_r($result); ?>
strtolower instead of strtoupper.Using strtoupper converts keys to uppercase. The filter keeps values greater than 10 with >.