0
0
PHPprogramming~20 mins

Integer type and behavior in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Integer Mastery in PHP
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this PHP code?

Consider the following PHP code snippet. What will it output?

PHP
<?php
$a = PHP_INT_MAX;
$b = $a + 1;
echo gettype($b);
?>
A"double"
B"integer"
C"string"
D"boolean"
Attempts:
2 left
💡 Hint

Think about what happens when you add 1 to the largest integer PHP can hold.

Predict Output
intermediate
2:00remaining
What is the value of $result after this code runs?

What will be the value of $result after executing this PHP code?

PHP
<?php
$result = (int) "123abc" + 10;
echo $result;
?>
A133
B10
C123abc10
D0
Attempts:
2 left
💡 Hint

How does PHP convert a string to an integer when the string starts with digits?

🔧 Debug
advanced
2:00remaining
What error does this PHP code raise?

What error or output will this PHP code produce?

PHP
<?php
$val = 1 << 65;
echo $val;
?>
AFatal error: Unsupported operand types
B1
CNotice: Bit shift exceeds integer size
D0
Attempts:
2 left
💡 Hint

Consider how PHP handles bit shifts larger than the integer size on 64-bit systems.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in PHP?

Which of the following PHP code snippets will cause a syntax error?

A<?php $num = 0123; echo $num; ?>
B<?php $num = 1,000; echo $num; ?>
C<?php $num = 1_000; echo $num; ?>
D<?php $num = 0x1A; echo $num; ?>
Attempts:
2 left
💡 Hint

Check how PHP handles numeric literals and commas.

🚀 Application
expert
3:00remaining
How many items are in the array after this code runs?

Given the following PHP code, how many items does the array $arr contain?

PHP
<?php
$arr = [];
$arr[1] = 'a';
$arr[1.5] = 'b';
$arr[true] = 'c';
$arr[null] = 'd';
$arr['1'] = 'e';
?>
A3
B4
C2
D1
Attempts:
2 left
💡 Hint

Remember how PHP converts array keys to integers.