RE: [PHP] Looping through a list - Newbie question

From: Date: Wed, 27 Aug 2003 13:53:41 +0000
Subject: RE: [PHP] Looping through a list - Newbie question
Groups: php.general 
Request: Send a blank email to php-general+get-160907@lists.php.net to get a copy of this message
There are a lot of methods. The most common is using an array: $_SESSION['sv_CampusList'] = Array ("1","2","3","4","5"); foreach($_SESSION['sv_CampusList'] as $id) { echo $id; } If you want to use sv_CampusList as string: $_SESSION['sv_CampusList'] = "1,2,4,5"; $tmpArr = explode(",",$_SESSION['sv_CampusList']); foreach($tmpArr as $id) { echo $id; } -----Mensaje original----- De: James Johnson [mailto:james@smb-studios.com] Enviado el: miércoles, 27 de agosto de 2003 4:45 Para: php-general@lists.php.net Asunto: [PHP] Looping through a list - Newbie question Hi, I have a list contained in a session var. I want to loop through the list, getting the value of the current item, then do a query based on that value. Is there an easy way to do this, or do I need to convert the list to an array first? In the code below, $id isn't being set. Here's my code (this is just testing stuff, sv_CampusList is set somewhere else): <?php session_start(); $_SESSION['sv_CampusList'] = "1,2,4,5"; for($i=1; $i<=strlen($_SESSION['sv_CampusList']); $i++){ $id = strpos($_SESSION['sv_CampusList'],$i); echo $id; } ?> Thanks, James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#160907) next »