NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help with while loop

Randal Rust randalrust at gmail.com
Mon Nov 27 15:10:33 EST 2006


I have always had trouble with trying to write these from scratch. The
code below is essentially what I have been working on, but it never
stops looping. What am I missing here?

<?php

$teams=array(
'Reds',
'Browns',
'Bengals',
'Cavaliers',
'Blue Jackets',
'Indians'
);

$unique=false;
$newTeam=$_POST['newTeam'];

function checkDuplicate($value){
	global $teams;
	$count=0;
	//do query here, return an array
	for($i=0; $i<count($teams); $i++){
		if($value==$teams[$i]){
			$count++;
			}
		}
	if($count == 0){
		//no matches
		return true;
		}
	else {
		//there are matches
		return false;
		}
	}
	
while(!$unique){
	$check=checkDuplicate($newTeam);
	if($check){ $unique=true; } else { $unique=false; }
	}

?>

-- 
Randal Rust
R.Squared Communications
www.r2communications.com



More information about the talk mailing list