Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:06:36+00:00 2026-05-25T21:06:36+00:00

Consider the following line of code: <?php $x = 10; $y = 7; echo

  • 0

Consider the following line of code:

<?php
$x = 10;
$y = 7;

echo '10 - 7 = '.$x-$y;
?>

The output of that is 3, which is the expected result of the calculation $x-$y. However, the expected output is:

10 – 7 = 3

My question therefore is, what happened to the string that I’m concatenating with the calculation? I know that in order to produce the result I expected, I need to enclose the arithmetic operation in parenthesis:

<?php
$x = 10;
$y = 7;

echo '10 - 7 = '.($x-$y);
?>

outputs

10 – 7 = 3

But since PHP does not complain about the original code, I’m left wondering what the logic behind the produced output in that case is? Where did the string go? If anyone can explain it or point me to a location in the PHP manual where it is explained, I’d be grateful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:06:37+00:00Added an answer on May 25, 2026 at 9:06 pm

    Your string '10 - 7 = ' is being concatenated with $x. Then that is being interpreted as an int which results in 10 and then 7 is subtracted, resulting in 3.

    For more explanation, try this:

    echo (int) ('10 - 7 = ' . 10); // Prints "10"
    

    More information on string to number conversion can be found at http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion

    If the string starts with valid numeric data, this will be the value used

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following three lines of Mathematica code and note that input line 1
Consider the following line of code: private void DoThis() { int i = 5;
Consider the following problem: A multi-line string $junk contains some lines which are encoded
Consider the following code <?php $username = root; $password = ; $host = localhost;
Consider the following piece of code: As you can see we are on line
I would like to ask probably simple question. Consider following php page: <p>Name of
Please consider the following code: <?php class MyException extends Exception {} function global_exception_handler($exception) {
consider the following code: if (matcher1.find()) { String str = line.substring(matcher1.start()+7,matcher1.end()-1); /*+7 and -1
Consider this following code (that retrieves the response from a HTTP request and prints
Consider the following line of code: things.Add(new Thing { ID = null, Name =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.