Jump to content


Photo

foreach has its own scope?


  • Please log in to reply
3 replies to this topic

#1 EriRyoutan

EriRyoutan
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 17 July 2006 - 05:57 PM

okay. what i'm trying to do is something like
foreach ($suits as $b)
{
	foreach($types as $a)
	{
		global $names;
		$names = $names + array($a . " of " . $b);
	}
}
so I could make a deck of cards. But for some reason, when I spit it out at the end, $names has the same value as it did when it started.

... any ideas?

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 06:01 PM

has globel $names the repeated varable.

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 06:01 PM

Because you are performing arithmetic to $names variable. The + sign is an Addition operater, You can not perform arithmetic to strings. Instead I think you will want to concate the two to gether like so:
$names .= array($a . " of " . $b);

#4 EriRyoutan

EriRyoutan
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 17 July 2006 - 06:04 PM

erk. too many languages, can't keep the stupid operators straight. x.x;

anyway, thanks. ... now i feel stupid... x.x;




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users