happy cat image

Start Web Coding

Your First step toward web coding,
Start Web Coding

change UI

Mathematical functions

A function that displays symbols every three digits: number_format()

number_format(number, number of decimal places to display, decimal places character, thousands marker)

    echo "Display symbol every three digits and specify the number of decimal places<br />";

    $num = 4567896213.989;

    echo "The number of destinations is {$num}. <br />";
    echo "1. Comma every three digits : ".number_format($num) . "<br />";
    echo "2. Comma and decimal point every three digits : " .number_format($num,"2",".",","). "<br />";
    echo "4. @ sign and decimal point every three digits # sign : ".number_format($num,"2","#","@");
php image

When only number_format($num) is used, it is separated by commas every 3 digits and the decimals disappear.
number_format($num, "2", ".", ",") Rounds to the second decimal place, and the third argument is the character used in character reality to separate the decimal points.
Put it.
The fourth is a marker to distinguish every three digits.

Return as an absolute value: abs() function

    echo "Replace -23 with an integer<br />";

    $a = -23;
    $b = abs($a);

    echo "The abs function was used and changed like this {$b}";
php image

Increasing the number of decimal places, abandoned, to round functions:
decimal rounding functions: ceil()
remove the decimal place: floor()
decimal places specified: round()
haebomyeon implemented as the source,

    echo "<b> round, round, round off </b> <br />";
    $a = 88.123456;
    echo "---------------------------------------- <br />";
    echo "Let's do the decimal with the variable \$a = 88.123456 <br />";

    echo "1. Unconditional raising .........".ceil($a)."<br /><br />";
    echo "2. Unconditionally discarded .........".floor($a)."<br /><br />";
    echo "3. Round less than 3 decimal places .....".round($a,3)."<br />";
php image

Calculate exponential power: pow()function

pow(calculate, exponential)

    echo "Exponential power of variable a=3, b=5 <br /><br />";

    $a = 3;
    $b = 5;
    $abpow = pow($a, $b);

    echo "The $b Exponential of $a is {$abpow}.";
php image

Calculate square root: sqrt()

    echo "Get the square root <br />";

    $a = 144;

    $asqrt = sqrt($a);

    echo "The square root of $a is {$asqrt}.<br />";
php image

log function: log(), log10()

Log(number, base) calculates the natural logarithm of the number entered, and log10 calculates the base 10.
log(number, base)

    echo "log() and log10() functions<br />";

    $a = 23;
    $val1 = log($a,5);
    $val2 = log10(23);
    echo "Calculate log when variable \$a = 23 <br />";

    echo "val1 = {$val1} <br />";
    echo "val2 = {$val2} <br />";
php image


It's called Pi, so I remember that my propressor said Choco Pie(korean cookie) pi should be seen as π ㅡㅡ^.

the value of pi is 3.141592....
M_PI when used as a constant

    echo "Width and circumference of circle using pi() function <br />";

    $a = 10;
    $val1 = $a * $a * pi(); // or replace pow($a, 2) * pi()
    $val2 = $a * 2 * M_PI;
    echo "When the radius of the circle \$a = {$a}<br />";

    echo "Width of the circle ... {$val1} <br />";
    echo "Circle of circle ... {$val2} <br />";
php image

Conversion between decimal and hexadecimal numbers: dechex(), hexdec()

dechex = convert decimal to hexadecimal
hexdec = translation of hexadecimal to decimal

    echo "dechex() , hexdec()<br />";

    $a = 342;
    $b = ad;
    $val1 = dechex($a);
    $val2 = hexdec($b);

    echo "in decimal {$a}, in hexadecimal {$b} <br />";
    echo "1. Convert decimal 342 to hexadecimal ... {$val1} <br />";
    echo "2. Convert hexadecimal ad to decimal ... {$val2} <br />";
php image

function to find the maximum and minimum values: max(), min()

max(argument1, argument2, argument3 ....... argument n)
min(argument1, argument2, argument3 ....... argument n)

    echo "max min <br />";

    $a = max(12,23,456,3);
    $b = min(12,23,456,3);

    echo "the value of maximum is {$a}<br />";
    echo "the value of minimum is {$b} <br />";
php image

Characters as well as numbers can be used. However, strings are treated as 0, and if there is the same string, both are 0, and the leftmost value is the maximum value.
In contrast, the minimum value is the right value of the same character. Then understand the source below.

    echo "max min <br />";

    $a = max('a','z');
    $b = min('a','z');

    echo " the value of maximum is  {$a} <br />";
    echo " the value of minimum is  {$b} <br />";
php image

True and false are also possible.
True evaluates to the maximum value and returns 1;
false evaluates to the minimum value and returns blanks.
If you understand the source below ...

    echo "max min <br />";

    $a = max(true,false);
    $b = min(true,false);

    echo " the value of maximum is  $a <br />";
    echo " the value of minimum is  $b <br />";
php image

Random value calculation: rand(), mt_rand()

Returns a random integer value.
If not set, returns a random number up to 32768.
To specify a specific range, set the min value max.

rand and mt_rand have the same function.
But mt_rand runs faster and generates progressive random numbers.
But how far is it going to be ;;;

Usage is
rand(minimum, maximum)
mt_rand(minimum, maximum)

    echo "rand()<br />";

    $a = rand();

    echo "When using the rand() function ....{$a} <br />";

    $b = rand(1,10);
    echo "When using the rand(1,10) function ... {$b} <br />";

    $c = mt_rand();
    echo "When using the mt_rand() function ... {$c} <br />";

    $d = mt_rand(1,10);
    echo "When using the mt_rand(1,10) function ... {$d} <br />";
php image

Array value sorting function: sort()
A function that sorts
the values ​​declared in the array from small to big or sorts them alphabetically and returns them as array variables.
For example, change array(3,4,6,2,8,5) from small to large.
sort(array variable, array method)
Three methods of array
sort_regualr: General comparison
sort_numeric: Numeric comparison
sort_string: Comparison by string

    echo "function sort() <br />";

    $a = array(23,9,15);

    echo "before using sort() <br />";

    for($c = 0; $c <= 2; $c++){
        echo "$a[$c]   <br />";

    echo "<br />";


    echo "after using sort() function <br />";

    for($c = 0;$c <= 2; $c++){
        echo " $a[$c] <br />";
php image

Function to get the number of arrays: count(), sizeof()
count_recursive is useful for counting the number of arrays.
count(array variable, [count_recursive])

    echo "Use count(), size() function to count number of arrays <br />";
    $a = array("MacBook Pro 16","MacPro","iPad Pro","iPhone Pro");

    $list = count($a);

    echo "the number of array \$a is  {$list}";
php image

This concludes the function tutorial and the next section goes to using mysql.
After the mysql course, we will move on to php sessions and cookies, and then to php and mysql linkage.

강좌로 돌아가기