Ace the Zend Certified PHP Engineer Challenge 2025 – Power Up Your PHP Skills!

Question: 1 / 400

What will be the output of the following PHP code: echo 5 + "10 apples";?

15 apples

15

The output of the code `echo 5 + "10 apples";` is indeed 15. This result is due to how PHP handles the addition operation when one of the operands is a string that contains numeric characters and additional non-numeric characters.

When the addition operator `+` is used, PHP attempts to convert the string to a number. In this case, the string "10 apples" begins with the digits '10', which PHP successfully converts to the integer value 10. The operation then performs the addition: 5 (the integer on the left) plus 10 (the converted value from the string) results in 15.

The non-numeric portion of the string, "apples", is ignored in this operation as PHP primarily focuses on the numeric part at the beginning of the string. Therefore, the final output is simply the numeric result of the addition, which is 15.

This behavior is consistent with PHP's type juggling feature, where the language attempts to convert between types as needed during operations like arithmetic.

Get further explanation with Examzify DeepDiveBeta

5 apples

10 apples

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy