How To Combine Two Strings Into One
RegisterLogin
How To Combine Two Strings Into One
Post Description: Today's Support Questions Is Regarding Php Programming We Received A Support Question Regarding How You Can Combine Or Put Together Different Strings To Execute As One
Tags: How, To, Combine, Two, Strings, Into, One
This Post Was Posted On Feb 05, 2010 By Webune Support #3110
Post Description: Today's Support Questions Is Regarding Php Programming We Received A Support Question Regarding How You Can Combine Or Put Together Different Strings To Execute As One
Tags: How, To, Combine, Two, Strings, Into, One
This Post Was Posted On Feb 05, 2010 By Webune Support #3110
How To Combine Two Strings Into One by Webune Support
Webune offers PHP hosting at low prices!!!
We received a support question regarding how you can combine or put together different strings to execute as one?
that was the question. as you can see its not very clear as to what the user wanted to achieve. after gathering more information, we became more aware that it really was a complicated question but the solution was simple.
we started to work with the user and ask him what he wanted to achieve or if we can get a code example of what he was trying to do. so this is what we got:
<?php
$PermsCmd1 = 'command 1';
$PermsCmd2 = 'command 2';
$PermsCmd3 = 'command 3';
$PermsCmd4 = 'command 4';
$PermsCmd5 = 'command 5';
for($counter =1; $counter <= 5; $counter++) {
echo ($PermsCmd.$counter).'<BR>';
}
?>
as you can see, we have a loop with 5 different strings, each string has begins with $PermsCmd and ends with a chronological number,
then we have a for loop. and we try to execute each string with this loop
what do you think the output is going to be?
this is what the user expected: command 1
command 2
command 3
command 4
command 5
but that was not the case, instead the ouput looked like this: 1
2
3
4
5
to achieve the output the user wanted, we would have to use an array and our code would look like this:
<?php
$PermsCmd['1'] = 'command 1';
$PermsCmd['2'] = 'command 2';
$PermsCmd['3'] = 'command 3';
$PermsCmd['4'] = 'command 4';
$PermsCmd['5'] = 'command 5';
for($counter =1; $counter <= 5; $counter++) {
echo ($PermsCmd[$counter]).'<BR>';
}
?>
now the output will look like this:
command 1
command 2
command 3
command 4
command 5
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
webune
#3760 1
its very easy to combine to strings into one,
example:
<?php
# declare strings
$foo1 = 'string 1';
$foo2 = ' string 2';
# combine both strings into a new string
$newfoo = $foo1.$foo2;
echo $newfoo;
?>
output:
string 1 string 2
example:
<?php
# declare strings
$foo1 = 'string 1';
$foo2 = ' string 2';
# combine both strings into a new string
$newfoo = $foo1.$foo2;
echo $newfoo;
?>
output:
string 1 string 2
Apr 11, 2010 Reply Report abuse
phpbcoder
#3758 2
i have a program coding for merging two strings into one
Apr 11, 2010 Reply Report abuse
©2011 Webune Forums - Sat Dec 24, 2011 11:16 am
Powered by: Webune Forums V3
Powered by: Webune Forums V3