Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays

Status
Not open for further replies.

axman505

Technical User
Joined
Jun 20, 2001
Messages
489
Location
US
Hello,

I have the following contents in an array:
0,1,3,7

Say i get a value, and if that value is 3, i want to cycle through the array with 3, 7, 0, 1

If the value is 1, then cycle through the array 1, 3, 7, 0

Is there a function to accomplish this?
 
check out sort() on php.net

I'm a little baffled as to why, if you posted maybe a little more info, ideas spring up like mushrooms :-)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Well, It is for a program at a universitry were the semester terms are 2040, 2041, 2043 and 2047 for this year. The 2 corresponds to the millenuym, the 04 is the last two digits of the year, and the the 0 is for winter, 1 for spring, 3 for summer and 7 for winter.

What i need is a function that will always produce the next 3 semesters to populate a drop down list.

Does this clarify things? :)
 
This sounds like an odometer problem:

Code:
<?php

function next_value ($current_value)
{
	$values_array = array (0, 1, 3, 7);
	$retval = FALSE;
	
	$pos = array_search($current_value, $values_array);
	
	if ($pos !== FALSE)
	{
		$retval = ($pos + 1) % count($values_array);
	}
	
	return $values_array[$retval];
}

$start = 3;

for ($counter = 0; $counter < 3; $counter++)
{
	$start = next_value($start);
	print $start. '<br>';

}
?>





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
This is what I ended up doing:

while ($semNum[0] != $semNumIn) {
$item = array_shift($semNum);
array_push($semNum,$item);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top