Falls mal jemand sowas braucht:
PHP
session_start();
//session_destroy();die;
$games['BFBC2'] = 'BFBC2';
$games['BF3'] = 'BF3';
$games['BFP4F'] = 'BFP4F';
$games['MOHW'] = 'MOHW';
$games['CRY1'] = 'CRY1';
$games['CRY2'] = 'CRY2';
$games['CRY3'] = 'CRY3';
function array_switch($array, $current='', $type='val')
{
function sortType($key, $val, $type)
{
if($type == 'key'){
return($key);
}else{
return($val);
}
}
function chkArray($array)
{
if(!isset($array)){
$missing = true;
}
elseif(is_bool($array)){
$_type_ = 'boolean';
}elseif(is_string($array)){
$_type_ = 'string';
}elseif($array == null){
$_type_ = 'null';
}
if(isset($missing)and $missing === true){
echo '<b>Warningsss</b>: Missing argument 1 for array_switch()';
return false;
}
if(isset($type)){
echo '<b>Warning</b>: array_switch() expects parameter 1 to be array, '.$_type_.' given';
return false;
}
}
if(chkArray($array) === false){
return false;
}
foreach($array as $key => $val){
if(!isset($selected)){
$selected = sortType($key, $val, $type);
}
$possibilities[] = sortType($key, $val, $type);
}
if(!isset($current)or empty($current)){
return($possibilities[key($possibilities)]);
}
foreach($possibilities as $key => $val){
if($current == $val){
if(@!$selected = $possibilities[$key+1]){
$selected = $possibilities[key($possibilities)];
}
return($selected);
}
}
}
// call array_switch()
$_SESSION['selected_game'] = array_switch($games, @$_SESSION['selected_game'], 'key' );
// test
foreach($games as $key => $val){
echo '<br />'.$val;
if($_SESSION['selected_game'] == $key){
echo '<';
}
}
Alles anzeigen
array_switch( array , current , type )
current: der zuletzt ausgegebene Wert (ohne macht kein sinn)
type: gibt an, ob der Wert von [key] oder => val durchlaufen werden soll
Verbesserungsvorschlöge erwünscht =)
(ich kenne next allerdings fehlte mir da bissl was)