さいころ振るfunction

<?php
function dice_role( $dice , $max_count ){
	$total = 0;
	$array = array();
	$array['dice_type'] = $dice.'D'.$max_count;
	for ($i = 0 ; $i < $dice ; $i++){
		$counts = mt_rand(1, $max_count);
		$array['dice'][] = $counts;
		$total = $total + $counts;
	}
	$array['total'] = $total;
	return $array;
}// end function
?>

↓ボーナス追加及びデフォルト設定

<?php
function dice_role( $dice , $max_count , $bonus = "0"){
	$total = 0;
	$array = array();
	$array['dice_type'] = $dice.'D'.$max_count;
	for ($i = 0 ; $i < $dice ; $i++){
		$counts = mt_rand(1, $max_count);
		$array['dice'][] = $counts;
		$total = $total + $counts;
	}
	$array['bonus'] = $bonus;
	$total = $total + $bonus;
	$array['total'] = $total;
	return $array;
}// end function
?>
<?php
function ini_role( $ply_ini , $emy_ini ){
	$array['ply'] = dice_role($ply_ini['initiative']['ini_dice'],$ply_ini['initiative']['ini_range'],$ply_ini['initiative']['ini_bonus']);
	$array['emy'] = dice_role($emy_ini['initiative']['ini_dice'],$emy_ini['initiative']['ini_range'],$emy_ini['initiative']['ini_bonus']);
	if($array['ply'][total] >= $array['emy'][total]){
		$array['flag'] = 1; //プレイヤー先攻
		$array['flag_text'] = '先制攻撃!';
	}else{
		$array['flag'] = 0; //プレイヤー後攻
		$array['flag_text'] = '先制を取られた!';
	}
	$array_dice = $array['ply']['dice'];
	$array_dice_text = '';
	foreach($array_dice as $dice){
		$array_dice_text .= $dice.'+';
	}
	$array_dice2 = $array['emy']['dice'];
	$array_dice_text2 = '';
	foreach($array_dice2 as $dice2){
		$array_dice_text2 .= $dice2.'+';
	}
	$array['dice_text'] = $ply_ini['unit_name'].'[ '.$array['ply']['dice_type'].':'.$array_dice_text.$array['ply']['bonus'].'= '.$array['ply']['total'].' ] || ';
	$array['dice_text'] .= $emy_ini['unit_name'].'[ '.$array['emy']['dice_type'].':'.$array_dice_text2.$array['emy']['bonus'].'= '.$array['emy']['total'].' ]';
	return $array;
}// end function
?>