Help - Search - Member List - Calendar
Full Version: hm? array and string?
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
roN @ work
Hi,

why is OutStr=0 after executing below code?
I just want to add all the Items in the Array into a String....the String
should look like this after:
[String]
<option>ElementA</option>
<option>ElementB</option>
<option>ElementC</option>
[/String]

CODE

$count=count($spamArray);
$outStr="";
for($j=0; $j<$count; $j++ )
 {
 $outStr+="<option>".$spamArray[$j]."</option>n";
 }

why is $OutStr=0?
Thank you!
--
chEErs
roN

Kimmo Laine
"roN @ work" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE
Hi,

why is OutStr=0 after executing below code?
I just want to add all the Items in the Array into a String....the String
should look like this after:
[String]
<option>ElementA</option
<option>ElementB</option
<option>ElementC</option
[/String]

CODE

$count=count($spamArray);
$outStr="";
for($j=0; $j<$count; $j++ )
{
$outStr+="<option>".$spamArray[$j]."</option>n";
}

why is $OutStr=0?
Thank you!


It's 0, because you are summing strings (which are evaluated 0, since they
are non-numeric) instead of concatenating. Use the concatenation operator .
instead.
Like this:
$outStr.="<option>".$spamArray[$j]."</option>n";

Thinking or reading the manual helps also.

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com

roN @ work
Kimmo Laine wrote:
QUOTE
"roN @ work" <[Email Removed]> wrote in message
news:[Email Removed]...
Hi,

why is OutStr=0 after executing below code?
I just want to add all the Items in the Array into a String....the
String should look like this after:
[String]
<option>ElementA</option
<option>ElementB</option
<option>ElementC</option
[/String]

CODE

$count=count($spamArray);
$outStr="";
for($j=0; $j<$count; $j++ )
{
$outStr+="<option>".$spamArray[$j]."</option>n";
}

why is $OutStr=0?
Thank you!


It's 0, because you are summing strings (which are evaluated 0, since
they are non-numeric) instead of concatenating. Use the concatenation
operator . instead.
Like this:
$outStr.="<option>".$spamArray[$j]."</option>n";

Thinking or reading the manual helps also.

yup, perfect. thank you! :)


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.