単体の数値の場合
最大値 = max(数値,数値[,数値...]);
mixed max ( mixed $value1 , mixed $value2 [, mixed $... ] )
最小値 = min(数値,数値[,数値...]);
mixed min ( mixed $value1 , mixed $value2 [, mixed $... ] )
例:
<?php header("Content-type: text/html; charset=utf-8"); $a = 100; $b = 2; $c = 55; echo max($a, $b, $c); echo min($a, $b, $c); ?>
1002
数値が含まれる配列の場合
最大値 = max(配列);
mixed max ( array $values )
最小値 = min(配列);
mixed min ( array $values )
例:
<?php header("Content-type: text/html; charset=utf-8"); $a = array(100,2,55); echo max($a); echo min($a); ?>
1002
切り上げ後の整数値 = ceil(丸め前の数値);
float ceil ( float $value )
切り捨て後の整数値 = floor(丸め前の数値);
float floor ( float $value )
四捨五入後の数値 = round(丸め前の数値[,小数点以下の桁数]);
float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )
例:
<?php header("Content-type: text/html; charset=utf-8"); $value = 10.35; echo ceil($value); echo floor($value); echo round($value); ?>
111010
<?php header("Content-type: text/html; charset=utf-8"); $value = 10.35; echo round($value, 1); ?>
10.4
<?php header("Content-type: text/html; charset=utf-8"); $value = 353.42; echo round($value, -2); ?>
400
例:
<?php header("Content-type: text/html; charset=utf-8"); $value = 353.42; echo round($value, -2); ?>
10.410.3
乱数 = rand([,最小値][,最大値])
int rand ( void ) int rand ( int $min , int $max )
例:
<?php header("Content-type: text/html; charset=utf-8"); $a = rand(1,100); echo $a . "<br>"; $a = rand(1,100); echo $a . "<br>"; $a = rand(1,100); echo $a . "<br>"; ?>
70
77
19
フォーマットされた文字列 = number_format(数値[,少数の桁数][,少数点の文字][,桁区切り文字])
string number_format ( float $number [, int $decimals = 0 ] ) string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
例:
<?php header("Content-type: text/html; charset=utf-8"); $value = 123456789.0123456; echo number_format($value); ?>
123,456,789
<?php header("Content-type: text/html; charset=utf-8"); $value = 123456789.0123456; echo number_format($value,4); ?>
123,456,789.0123
<?php header("Content-type: text/html; charset=utf-8"); $value = 123456789.0123456; echo number_format($value,4,"-","="); ?>
123=456=789-0123