Complete the code to declare an integer variable with value 10.
<?php
$number = [1];
echo $number;
?>The value 10 without quotes is an integer in PHP.
Complete the code to check if a variable is an integer using a built-in function.
<?php $var = 5; if ([1]($var)) { echo "Integer"; } else { echo "Not integer"; } ?>
is_string or is_float instead of is_int.is_numeric which returns true for floats and numeric strings too.The function is_int() checks if a variable is an integer.
Fix the error in the code to correctly add two integers and print the result.
<?php $a = 7; $b = 3; $sum = $a [1] $b; echo $sum; ?>
. which concatenates strings instead of adding numbers.The plus sign + adds two numbers in PHP. The dot . is for string concatenation.
Fill both blanks to create an array of squares for numbers 1 to 5 using a loop.
<?php $squares = []; for ($i = 1; $i [1] 5; $i++) { $squares[] = $i [2] $i; } print_r($squares); ?>
The loop runs while $i is less than or equal to 5. The square is calculated by multiplying $i by itself.
Fill all three blanks to create an associative array with keys as numbers and values as their cubes, only for numbers greater than 2.
<?php $cubes = []; foreach (range(1, 5) as [1]) { if ([2] > 2) { $cubes[[3]] = [2] * [2] * [2]; } } print_r($cubes); ?>
$val.The variable $num is used for the loop and conditions consistently to represent each number.