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 1098259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:33:12+00:00 2026-05-17T00:33:12+00:00

Watch following code: $a = ‘Test’; echo ++$a; This will output: Tesu Question is,

  • 0

Watch following code:

$a = 'Test';
echo ++$a;

This will output:

Tesu

Question is, why ?

I know "u" is after "t", but why it doesn’t print "1" ???

PHP Documentation:

Also, the variable being incremented
or decremented will be converted to
the appropriate numeric data
type—thus, the following code will
return 1, because the string Test is
first converted to the integer number
0, and then incremented.

  • 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-17T00:33:13+00:00Added an answer on May 17, 2026 at 12:33 am

    In PHP you can increment strings (but you cannot “increase” strings using the addition operator, since the addition operator will cause a string to be cast to an int, you can only use the increment operator to “increase” strings!… see the last example):

    So "a" + 1 is "b" after "z" comes "aa" and so on.

    So after "Test" comes "Tesu"

    You have to watch out for the above when making use of PHP’s automatic type coercion.

    Automatic type coercion:

    <?php
    $a="+10.5";
    echo ++$a;
    
    // Output: 11.5
    //   Automatic type coercion worked "intuitively"
    ?>
    

    No automatic type coercion! (incrementing a string):

    <?php
    $a="$10.5";
    echo ++$a;
    
    // Output: $10.6
    //   $a was dealt with as a string!
    ?>
    


    You have to do some extra work if you want to deal with the ASCII ordinals of letters.

    If you want to convert letters to their ASCII ordinals use ord(), but this will only work on one letter at a time.

    <?php
    $a="Test";
    foreach(str_split($a) as $value)
    {
        $a += ord($value);  // string + number = number
                            //   strings can only handle the increment operator
                            //   not the addition operator (the addition operator
                            //   will cast the string to an int).
    }
    echo ++$a;
    ?>
    

    live example

    The above makes use of the fact that strings can only be incremented in PHP. They cannot be increased using the addition operator. Using an addition operator on a string will cause it to be cast to an int, so:

    Strings cannot be “increased” using the addition operator:

    <?php
       $a = 'Test';
       $a = $a + 1;
       echo $a;
    
       // Output: 1
       //  Strings cannot be "added to", they can only be incremented using ++
       //  The above performs $a = ( (int) $a ) + 1;
    ?>
    

    The above will try to cast “Test” to an (int) before adding 1. Casting “Test” to an (int) results in 0.


    Note: You cannot decrement strings:

    Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.

    The previous means that echo --$a; will actually print Test without changing the string at all.


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

Sidebar

Related Questions

I am trying to watch videos in my iphone app using the following code:
When trying to run the following program code, this error occurred; Input string was
I'm using the following code to watch for changes to a given SELECT element.
I'm just toying around to watch how defining operators work. The following code gives
I have a UIWebView with the following embed code in it: <embed id=yt src=http://www.youtube.com/watch?v=1T6YM7RE5wQ
So, look at the following code below- my first question is, how can I
Why when I watch the build output from a VC++ project in VS do
I have a file watch directory named FileWatch C:\Users\MyFolder\FileWatch\Test The FileWatch folder is the
Something like this: sass --watch style.css:(other than root directory) //or sass --watch (other directory
I am using the following code: preg_match('/url_encoded_fmt_stream_map=(.*?)&/', $response, $fmt_url) to grab the url_encoded_fmt_stream_map contents

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.