Complete the code to convert the string to an integer.
<?php $value = "123"; $number = ([1])$value; echo gettype($number); // outputs 'integer' ?>
In PHP, casting a string to int converts it to an integer type.
Complete the code to check if the string '10 apples' equals the number 10 using ==.
<?php $result = ('10 apples' [1] 10); echo $result ? 'true' : 'false'; ?>
The == operator in PHP compares values after type juggling, so '10 apples' == 10 is true.
Fix the error in the code to correctly add a string number and an integer.
<?php $a = "5"; $b = 3; $sum = $a [1] $b; echo $sum; // should output 8 ?>
The + operator adds numbers. PHP converts the string '5' to number 5 automatically.
Fill both blanks to create an array with keys as strings and values as integers using type juggling.
<?php $items = ["1" => 100, "2" => 200]; foreach ($items as $key => $value) { echo (int) $key [1] $value . "\n"; } ?>
Casting the string key to int and adding the value sums numbers correctly.
Fill all three blanks to filter an array of strings, keeping only those that convert to integers greater than 10.
<?php $values = ["5", "15", "abc", "20"]; $result = array_filter($values, function($val) { return (int) $val [1] 10; }); print_r($result); ?>
The > operator filters values where the integer conversion is greater than 10.