team2005
asked on
Echo variable 2 times ?
Hi!
Have this PHP code
$search['email'] = 'test';
echo $search['email'];
This show : testtest
Why is the result to screen not : test ?
Have this PHP code
$search['email'] = 'test';
echo $search['email'];
This show : testtest
Why is the result to screen not : test ?
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:
http://php.net/manual/en/function.var-dump.php
http://php.net/manual/en/function.var-dump.php
var_dump($search);
Going forward, there is an excellent guide that teaches how to ask technical questions. It's called The SSCCE
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
Do you get
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'
If you do this
$search['email']='Something Else';
echo $search['email'];
Do you get
testSomething Else
OrSomething ElseSomething Else
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'
ASKER
Hi Julian!
It echo : Something ElseSomething Else
It echo : Something ElseSomething Else
You need to post your full code so we can see the context.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
If cannot, try changing the line echo $search['email']; to
Open in new window
and see how the string is displayed.