入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

php约瑟夫环

创建时间:2015-06-02 投稿人: 浏览次数:646
<?php 
function popChar($str , $m , $current = 0){
    $number = count($str);
    $num = 1;
    if(count($str) == 1){
        echo $str[0];
        return;
    }else{
        while($num++ < $m){
            $current++ ;
            $current = $current%$number;
        }
        echo $str[$current]." ";
        array_splice($str , $current , 1);
	//unset($str[$current]);
	//$str = array_merge($str);
        popChar($str , $m , $current);
    }
}
//$str = array(1 , 2 , 3 , 4 , 5 , 6 , 7, 8 , 9 , 10);  
$str = array("a","b","c","d","e","f","g","h");  
$m = 4; 
popChar($str , $m);
?>

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。