PHP mathematical operations and data processing instance analysis, data processing instance Analysis _ PHP Tutorial

Source: Internet
Author: User
PHP mathematical operations and data processing instance analysis, data processing instance analysis. PHP mathematical operations and data processing instance analysis, data processing instance analysis this article describes the PHP mathematical operations and data processing methods. For your reference, I. PHP Mathematical Computation and Data processing instance analysis and data processing instance analysis

This article describes PHP mathematical operations and data processing methods. We will share this with you for your reference. The details are as follows:

I. numerical data type

In PHP, the use of numeric or numeric data and mathematical functions is very simple. Basically, two data types are to be processed: floating point and integer. The internal representation of floating point numbers and integer values is double and int of the C data type, respectively. Similar to C and PHP, these data types follow the same set of rules.

PHP is a loose scripting language. variables can change the data type based on computing requirements. This allows the engine to dynamically complete type conversion. Therefore, if the computation contains a value and a string, the string is converted to a value before computation, and the value is converted to a string before connection with the string.

<?php$a = '5';$b = 7 + $a;echo "7 + $a = $b";?>

PHP provides a large number of functions to check the data types of variables. There are three functions that can check whether a variable contains a numeric value or, more specifically, whether the variable is a floating point number or an integer.
The is_numeric () function checks whether the value passed in as a parameter is a numerical value.

The is_int () and is_float () functions are used to check specific data types. If an integer or floating-point number is input, these functions return true; otherwise, false is returned, even if a string with a valid value is input, false is returned.

You can also force the engine to change the data type. This is called forced type conversion. you can add (int), (integer), (float), (double), or (real) before a variable or value, you can also use the intval () or floatval () functions.

II. random number

Random numbers are a science. There are already many different random number generator implementations. PHP implements two types: rand () and mt_rand (). The rand () function is a simple package for random functions defined in libc (one of the basic libraries provided by the compiler used to build PHP. Mt_rand () is a good alternative implementation, providing many well-designed features, and mt_rand () is even faster than the version in libc.

Both functions provide some functions to obtain the value of MAX_RAND. Rand () is getrandmax (), mt_rand () is mt_getrandmax ();

3. Format data

In addition to warning and error information, most PHP outputs are generated using functions such as echo, print (), and printf. These functions convert parameters into a string and send it to the client application.
The number_format () function converts integers and floating-point values into a readable string representation.

<?php $i = 123456;$si = number_format($i,2,".",",");echo $si;?>

IV. mathematical functions

Abs () absolute value
Floor () Rounding
Ceil () returns an integer
Round () Rounding
Min () calculates the minimum value or the minimum value in the array.
Max () calculates the maximum value in the maximum array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.