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

  • Home
  • SEARCH
  • 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 8535415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:25:32+00:00 2026-06-11T10:25:32+00:00

I’ve came across an example in print manual of php.net. that stats. echo 3

  • 0

I’ve came across an example in print manual of php.net. that stats.

   echo 3 . print(2) . print(4) . 5 . 'c' . 
   print(6) . print(7). 'b' .print(8) . 'a';

which prints 8a7b16145c12131. But how?

  • 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-06-11T10:25:33+00:00Added an answer on June 11, 2026 at 10:25 am

    I think you just got fooled by presence of concatenation operator . which made you assume that the only output from this code would come from echo and all other functions would only “contribute” to echo’s argument. It is wrong, of course, because you assumed that print() somehow changed its behaviour and returns its output there, instead of printing it out instantly (upon a call) to the output stream. The only thing you concatenate there are strings and each print()‘s ** return value**. And the latter, according to the manual is always “1”. Change print(), to sprintf() and all the “magic” will be gone.

    BTW it is good brainer – can keep busy for a while 🙂

    EDIT ON OP’s REQUEST

    The “culprit” here is print. It is worth noting that it is not a real function but language construct which influences the way it is handled during evaluation. For example:

    echo 3 . print(2) . 'c';
    

    produces:

    2c31
    

    But if you move print into function like this:

    function x($a) { return print $a; }
    echo 3 . x(2) . 'c';
    

    then the output will look more sane:

    231c
    

    If you care about details you will need to lurk into Zend Engine sources, but in general, such syntax is likely used for anything useful. Remembering print is tricky suffices.

    And why we see “231c” anyway? It is because echo arguments needs first to be evaluated – without that PHP do not really know what to echo (or could know partially). So PHP goes more/less this way:

    • get “3” to our temporary string
    • call function x(2) – since this function does print, our argument (“2”) will be instantly printed to the output. Function returns “1” because print always return “1” (see manual) so PHP concatenates “1” to so we now have “31”,
    • get ‘c’ and concatenate, so we now have “31c”
    • echo our temporary string.

    Note that in fact echo outputs ’31c’ only. Prefixing “2” is there because it is print output and we had not used LF (or <br /> if you are not testing this in console) in meantime so all output goes into one line. If you change the code to use LF (or <br />):

    function x($a) { return print $a; }
    $f = 3 . x(2) . 'c';
    echo "\n${f}";
    

    then the output will be:

    2
    31c
    

    Hope this helps.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.