PHP variable Function Learning Summary _php Example

Source: Internet
Author: User
Tags binary to decimal generator natural logarithm rounds square root value of pi wrapper

In the previous article to introduce you to PHP variable variables, today through this article to introduce you to PHP variable functions, specific details are as follows.

PHP supports the concept of variable functions. This means that if a variable name is followed by parentheses, PHP will look for a function with the same name as the value of the variable and try to execute it. Variable functions can be used to implement some uses including callback functions, function tables, and so on.

Variable functions cannot be used for example Echo,print,unset (), Isset (), Empty (), Include,require, and similar language structures. You need to use your own wrapper functions to make these structures as variable functions.

Example #1 Variable Function example

<?php
function foo () {
 echo "in foo () <br/>\n";
}
function bar ($arg = ') {
 echo ' in Bar (); Argument was ' $arg '. <br/>\n ";
}
wrapper function
Echoit ($string)
{
 echo $string
using echo $func = ' foo ';
$func ();  This calls foo ()
$func = ' bar ';
$func (' Test '); This calls bar ()
$func = ' echoit ';
$func (' Test '); This calls Echoit ()
?>

You can also invoke the method of an object using the syntax of a mutable function.

<?php
class Foo
{
 function Variable ()
 {
  $name = ' Bar ';
  $this-> $name (); This calls the bar () method
 }
 function Bar ()
 {
  echo ' this is bar ';
 }
}
$foo = new Foo ();
$funcname = "Variable";
$foo-> $funcname (); This calls $foo->variable ()
?>

When a static method is invoked, the function call takes precedence over the static property:

Example #3 Variable methods and static properties examples

<?php
class Foo
{
 static $variable = ' static property ';
 static function Variable ()
 {
  echo ' method Variable called ';
 }
}
echo Foo:: $variable; This is prints ' static property '. It does need a $variable in this scope.
$variable = "variable";
Foo:: $variable (); This calls $foo->variable () reading $variable in this scope.
? >

The list of methods that can use a variable function is as follows:

<?php Array_diff_assoc () Array_diff_key () Array_diff_uassoc () array () Array_intersect_ukey () Array_map () Array_ Merge () array_merge_recursive () Array_multisort () Array_push () Array_replace () array_replace_recursive () Array_
Unshift () Call_user_func () Call_user_method () compact () Dba_open () Dba_popen () echo () Forward_static_call () fprintf ()
FSCANF () httprequestpool_construct () Ibase_execute () Ibase_set_event_handler () ibase_wait_event ()-Isset () list () Maxdb_stmt_bind_param () Maxdb_stmt_bind_result () Mb_convert_variables () Newt_checkbox_tree_add_item () Newt_grid_h_ Close_stacked () newt_grid_h_stacked () newt_grid_v_close_stacked () newt_grid_v_stacked () Newt_win_choice () Newt_win_ Entries () Newt_win_menu () Newt_win_message () newt_win_ternary () Pack (), printf () register_shutdown_function () register _tick_function () Session_register () setlocale () sprintf () sscanf () unset () Var_dump () W32api_deftype () Dtype () w32api_invoke_function () Wddx_add_vars () Wddx_serialize_vars ()

Here is a brief introduction to the PHP math function

Introduction to PHP Math

The mathematical (math) function handles values within the integer and float ranges.

PHP Math function

PHP: Indicates the earliest version of PHP that supports this function.

function Description PHP
ABS () Absolute. 3
ACOs () Inverse cosine. 3
Acosh () Inverse hyperbolic cosine. 4
ASIN () Anyway chord. 3
Asinh () Inverse hyperbolic sine. 4
Atan () Cut it anyway. 3
ATAN2 () Two parameters of the tangent. 3
Atanh () Inverse hyperbolic tangent. 4
Base_convert () Converts a number between arbitrary systems. 3
Bindec () Converts the binary to decimal. 3
Ceil () Rounds up to the nearest integer. 3
cos () Cosine. 3
Cosh () Hyperbolic cosine. 4
Decbin () Converts the decimal system to binary. 3
Dechex () Converts the decimal system to 16. 3
DECOCT () Converts the decimal system to octal. 3
Deg2rad () Converts an angle to radians. 3
EXP () Returns the value of Ex . 3
EXPM1 () Returns the value of Ex -1. 4
Floor () Rounds down to the nearest integer. 3
Fmod () Returns the floating-point number remainder of a division. 4
Getrandmax () Displays the maximum possible value of the random number. 3
Hexdec () Converts the 16 to decimal. 3
Hypot () Calculates the hypotenuse length of a right-angled triangle. 4
Is_finite () Determine if it is a finite value. 4
Is_infinite () Determines whether it is an infinite value. 4
Is_nan () Determines whether the value is legal. 4
Lcg_value () Returns a pseudo random number with a range of (0, 1). 4
Log () Natural logarithm. 3
LOG10 () Logarithm with a base of 10. 3
LOG1P () Returns log (1 + number). 4
Max () Returns the maximum value. 3
Min () Returns the minimum value. 3
Mt_getrandmax () Displays the maximum possible value for a random number. 3
Mt_rand () Returns a random integer using the Mersenne twister algorithm. 3
Mt_srand () Seeding Mersenne Twister Random number generator. 3
Octdec () Converts octal to decimal. 3
Pi () Returns the value of pi. 3
POW () Returns the Y-second side of X. 3
Rad2deg () Converts the number of radians to the number of angles. 3
RAND () Returns a random integer. 3
Round () Rounding the floating-point numbers. 3
Sin () Sinusoidal. 3
Sinh () Hyperbolic sine. 4
sqrt () Square root. 3
Srand () Sow the seed of the random number generator. 3
Tan () Tangent. 3
Tanh () Hyperbolic tangent.

PHP Math Constants

constant Name constant Name constant Value PHP
M_e E 2.7182818284590452354 4
M_euler Euler Constants 0.57721566490153286061 5.2.0
M_lnpi Log_e (PI) 1.14472988584940017414 5.2.0
M_ln2 Log_e 2 0.69314718055994530942 4
M_ln10 Log_e 10 2.30258509299404568402 4
m_log2e Log_2 E 1.4426950408889634074 4
m_log10e Log_10 E 0.43429448190325182765 4
M_pi Pi 3.14159265358979323846 3
M_pi_2 Pi/2 1.57079632679489661923 4
M_pi_4 Pi/4 0.78539816339744830962 4
M_1_pi 1/pi 0.31830988618379067154 4
M_2_pi 2/pi 0.63661977236758134308 4
M_sqrtpi sqrt (PI) 1.77245385090551602729 5.2.0
M_2_sqrtpi 2/sqrt (PI) 1.12837916709551257390 4
M_sqrt1_2 1/SQRT (2) 0.70710678118654752440 4
M_sqrt2 sqrt (2) 1.41421356237309504880 4
M_sqrt3 SQRT (3) 1.73205080756887729352 5.2.0

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.