1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP Developer''''s Dictionary- P23 pdf

5 252 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 362,24 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

echo bcmod15,3;//returns 0 echo bcmod15,4;//returns 3 bcmul Syntax string bcmulstring left_operand, string right_operand, [int scale] Description The bcmul function calculates the pr

Trang 1

echo bcmod(15,3);//returns 0

echo bcmod(15,4);//returns 3

bcmul()

Syntax

string bcmul(string left_operand, string right_operand, [int scale])

Description

The bcmul() function calculates the product of the left and right operands The

scale parameter is optional and indicates the number of digits to the right of the

decimal point in the result If scale is omitted, it defaults to 0

echo bcmul(2.005,3.009,2);//result is 6.00

echo bcmul(10.00,0.500,2);//result is 5.00

echo bcmul(0.500,0.500,2);//result is 0.25

bcpow()

Syntax

string bcpow(string x, string y, [int scale])

Description

The bcpow() function returns a string that is x raised to the power y Note that y

must have a scale of 0 or a warning will occur The scale parameter is optional and

indicates the number of digits to the right of the decimal point in the result If scale

is omitted, it defaults to 0

echo bcpow(2.005,3,2);//result is 8.00

echo bcpow(4.25,2,2);//result is 18.06

bcscale()

Syntax

Trang 2

string bcscale(int scale)

Description

The bcscale() function sets the scale that all subsequent bcmath functions will use

when none is explicitly indicated The scale parameter is used to indicate the

desired precision in the result—specifically, the number of digits to the right of the decimal point

bcsqrt()

Syntax

string bcsqrt(string operand, int scale)

Description

The bcsqrt() function calculates the square root of the operand The scale

parameter is an optional parameter that indicates the number of digits to the right of the decimal point in the result If scale is omitted, it defaults to 0

echo bcsqrt(4.00,2);//result is 2.00

echo bcsqrt(4.25,2);//result is 2.06

bcsub()

Syntax

string bcsub(string left_operand, string right_operand, int [scale])

Description

The bcsub() function calculates the difference by subtracting the right_operand from the left_operand The scale parameter is an optional parameter indicating

the number of digits to the right of the decimal point in the result If scale is

omitted, it defaults to 0

echo bcsub(4.005,2.009,2);//result is 2.00

echo bcsub(1.00,2.00,2);//result is -1.00

Trang 3

Array

Arrays in PHP can serve many useful roles, but the main reason to use an array is to organize groups of related values In PHP, each element in an array has a

corresponding index (also referred to as key) and a value The index can be a

number or it can be a string, whereas the value can be of any type Arrays of multiple dimensions are possible because an array element itself can in turn be an array When an array is created, an internal pointer is initialized to the first element

of an array This pointer is used in several functions to traverse the elements of the array Other roles that arrays can play in PHP include representing a stack or a queue data structure The array functions provide powerful tools for managing and processing related data

array()

Syntax

array array( )

Description

The array() language construct returns an array made up of the given parameters The parameters can indicate an index or key with the => operator Each element in

an array is comprised of a key and a value If a key isn't defined when creating an array, the position of the element in the array will be used with the first element of the array at 0

$array1 = array(1,1);//indexed array starting at zero

$array2 = array("heads"=>1,"tails"=>0);//associative array

$array3 = array($array1,$array2);//array of arrays

array_count_values()

Syntax

array array_count_values(array input)

Description

The array_count_values() function, which was added in PHP 4.0b4, returns an array indicating the frequency of values in the input array The resulting array has

the values in the input array as the keys and the corresponding frequency of each

Trang 4

$somearray = array(1, "ABC", 1);

array_count_values($somearray);//returns array( 1=>2, "ABC"=>1 )

array_diff()

Syntax

array array_diff(array array1, array array2 [, array ])

Description

The array_diff() function, which was added in PHP 4.0.1, returns all the values contained in array1 that are not in any of the other arrays given

$array1 = array(1,2,3);

$array2 = array(2,3);

$array3 = array_diff($array1,$array2);//$array3 = (1)

array_flip()

Syntax

array array_flip(array trans)

Description

The array_flip() function , which was added in PHP 4.0b4, returns an array that is made up of all the flipped values in the trans array To flip means to swap the

values with their corresponding keys

$array1 = array("a"=>"1");

$array2 = array_flip($array1);

echo $array2["1"];//returns a

array_intersect()

Syntax

Trang 5

array array_intersect(array array1 array array2 [, array ])

Description

The array_intersect() function, which was added in PHP 4.0.1, returns an array containing the values of array1 that are also present in all the other given

parameters

$array1 = array(1,2,3);

$array2 = array(2,3);

$array3 = array(3,4);

$array4 = array_intersect($array1,$array2,$array3);//$array3 = (3)

array_keys()

Syntax

array array_keys(array input, mixed [search_value])

Description

The array_keys() function, which was added in PHP 4.0, returns both numeric and string keys from the input array The search_value parameter is optional and it

indicates that only keys with this corresponding value should be returned

$inarray = array(1,"two"=>1,0,1,1);

$outarray = array_keys($inarray,1);//$outarray = (0,"two",2,3)

array_merge()

Syntax

array array_merge(array array1, array array2, [ ])

Description

The array_merge() function, which was added in PHP 4.0, appends multiple arrays together to form one single array In the case that more than one array shares the same string key, the latter array will overwrite the previous array With similar

Ngày đăng: 07/07/2014, 05:20

TỪ KHÓA LIÊN QUAN