We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,166 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Exception in foreach loop, how to?

Hi,

I want to get information from each session set, EXCEPT when the session name is 'navigation':
So basically: Create an exception for the session called 'navigation'..

foreach ($_SESSION as $name => $value) 
// $name = navn på session: f.eks. 1 eller 2 - $value indeholder antallet der er i kurven)
{
 if(substr($_SESSION,0,10) != 'navigation') // Doesnt work
   {
	echo $name .' har ' .$value.' varer<br />';
   }
}

How do I do this, without getting the information from the session called 'navigation'?
Regards, Klemme

2
Contributors
4
Replies
23 Minutes
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
klemme
Posting Whiz
311 posts since Mar 2011
Reputation Points: 18
Solved Threads: 8
Skill Endorsements: 0

$_SESSION is an array. Don't you want to check $value ?

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,459
Skill Endorsements: 86
foreach ($_SESSION as $name => $value) 
// $name = navn på session: f.eks. 1 eller 2 - $value indeholder antallet der er i kurven)
	{
		if (substr($name,0,5) == 'cart_')
		{	
			echo $name .' har ' .$value.' varer<br />';
		}
	}

This works though.

It is for a shopping cart using sessions - But I have another session declared elsewhere on the site, so I needed to make an exception for that, which my logic screwed up.

I only want to check the sessions named: 'cart_'.

klemme
Posting Whiz
311 posts since Mar 2011
Reputation Points: 18
Solved Threads: 8
Skill Endorsements: 0

Arh you mean I could just check if $name == 'navigation'{then do something, or not}?

klemme
Posting Whiz
311 posts since Mar 2011
Reputation Points: 18
Solved Threads: 8
Skill Endorsements: 0

Depends on how you set it. But yes, I think that is what you want.

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,459
Skill Endorsements: 86
Question Answered as of 1 Year Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0641 seconds using 2.65MB