Echo variable 2 times ?


Have this PHP code

$search['email'] = 'test';
echo $search['email'];

This show : testtest

Why is the result to screen not : test ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian TaoSenior Business Solutions ConsultantCommented:
It shouldn't.  It's more likely coming from some other part of your code.  Can you post/attach your entire script?
If cannot, try changing the line echo $search['email']; to
echo "-start-" . $search['email'] . "-end-";

Open in new window

and see how the string is displayed.
Ray PaseurCommented:
This appears to be an isolated bit of a script and we cannot see the data you're using, so there is really no way to know what is happening without more information.  Brian Tao has given you one good suggestion.  When I'm not sure what a variable contains (in this case, the $search array). I visualize the variable and its contents with something like this:

Open in new window

Going forward, there is an excellent guide that teaches how to ask technical questions.  It's called The SSCCE
Julian HansenCommented:
Somewhere in your code before the assignment of 'test' to $search['email'] you are doing an echo that is creating the first 'test'.
If you do this

$search['email']='Something Else';
echo $search['email'];

Open in new window

Do you get
testSomething Else

Open in new window

Something ElseSomething Else

Open in new window

I am guessing you get the first output - which means look earlier in your code to see where there is potentially another echo statement that output's the first 'test'
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

team2005Author Commented:
Hi Julian!

It echo : Something ElseSomething Else
Julian HansenCommented:
You need to post your full code so we can see the context.
Ray PaseurCommented:
Usually your text editor or IDE has a "find" function.  You might use the finder to look for the string $search['email'] throughout your scripts.  Then follow the logic in each script that contains a reference to this string.  Note that I said scripts, not script.  With hiccups like this one there may be more than one script involved in creating output.  PHP include() statements or similar may be in play.  Or the test may be running the wrong version of a script, due to a mistaken URL path.  So cast your net wide when you look for the issues, because there is no guarantee that the error will be obvious in the first script you examine.  Once you find every occurrence of $search['email'] you should be able to see all the places it is used in print/echo statements, or all the places that it is copied to other variables that use print/echo.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
team2005Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.