PHP mathematical operations and data processing examples Analysis Ansys finite element Analysis example ANSYS static analysis Ansys Thermal Analysis Real

Source: Internet
Author: User
Tags getting started with php mathematical functions
In this paper, the mathematical operations and data processing methods of PHP are described. Share to everyone for your reference, as follows:

A Numeric data type

In PHP, the use of numeric or numeric data and mathematical functions is simple. Basically, there are two types of data to work with: floating-point numbers and integers. The internal representations of floating-point and integer values are the C data type double and int respectively. These data types, similar to those in c,php, follow the same set of rules.

PHP is a loosely typed scripting language, and variables can change the data type based on the requirements of the calculation. This allows the engine to perform type conversions dynamically. Therefore, if the calculation contains numeric values and strings, the string is converted to a numeric value before the calculation is completed, and the value is converted to a string before the string is concatenated.

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

PHP provides a number of functions to check the data type of a variable. There are 3 functions to check if a variable contains a numeric value, or more specifically, to check whether the variable is a floating-point number or an integer.
The function is_numeric () checks to see if the value passed in as a parameter is numeric.

The functions Is_int () and is_float () are used to check the specific data type. If an integer or floating-point number is passed in, the functions return true, otherwise false is returned, even if the string passed in with a valid numeric representation returns FALSE.

You can also force the engine to change the data type. This is called a type cast, which can be implemented either by adding (int), (integer), (float), (double), or (real) before a variable or value, or by using the function intval () or floatval ().

Two Random number

The random number itself is a science. There have been many different implementations of random number generators. PHP implements two of these: rand () and Mt_rand (). The rand () function is a simple wrapper for a random function defined in libc (one of the basic libraries provided by the compiler that is used to build PHP). Mt_rand () is a good alternative implementation that provides a lot of well-designed features, and Mt_rand () is even faster than the version in libc.

Two functions provide some functions to get the value of Max_rand. Rand () is Getrandmax (), Mt_rand () is Mt_getrandmax ();

Three Formatting data

In addition to warnings, errors and other information, most of PHP's output is generated using functions such as ECHO, print (), and printf (). These functions convert the parameters into a string and send them to the client application.
The Number_format () function converts integers and floating-point values to a readable string representation.

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

Four Mathematical functions

ABS () absolute value
Floor () de-rounding method
Ceil () into a method to take the whole
Round () rounding
Min () to find minimum or minimum value in array
Max () max value in array

More readers interested in PHP related content can view this site: "Summary of PHP operations and operator usage," PHP Network Programming Tips Summary, "PHP Basic Grammar Primer Tutorial", "PHP operation Office Document tips summary (including word,excel,access, ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

The above describes the PHP mathematical operations and data processing examples of analysis, including the case analysis, PHP content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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: info-contact@alibabacloud.com 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.