<?php 
function Jotapata($n=41,$k=3,$m=1){$m--;
	$prisoners=array_fill(0,$n,false);
	$deadpool=1;
	$order=0;
	while((array_sum(array_count_values($prisoners))<$n)){
		foreach($prisoners as $thisPrisoner=>$dead){
			if(!$dead){
				if($deadpool==$k){
					$order++;
					
					$prisoners[$thisPrisoner]=((($n-$m)>($order)?$order:(($n)==$order?'Call me *Titus Flavius* Josephus':'Joe\'s friend '.(($order)-($n-$m-1)))));
					$deadpool=1;
				}else{$duckpool++;}
			}
		}
	}
	return $prisoners;
}
echo '<pre>'.print_r(Jotapata(41,3,5),true).'<pre>';