PHP Developer''''s Dictionary- P23 pdf

5 252 0
PHP Developer''''s Dictionary- P23 pdf

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

Thông tin tài liệu

PHP Developer’s Dictionary IT-SC book 110 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 PHP Developer’s Dictionary IT-SC book 111 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 PHP Developer’s Dictionary IT-SC book 112 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 key in the input array as its value. PHP Developer’s Dictionary IT-SC book 113 $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 PHP Developer’s Dictionary IT-SC book 114 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 numeric keys, this doesn't happen—the arrays are simply appended. . is -1.00 PHP Developer’s Dictionary IT-SC book 112 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. Syntax PHP Developer’s Dictionary IT-SC book 114 array array_intersect(array array1 array array2 [, array ]) Description The array_intersect() function, which was added in PHP 4.0.1,. PHP Developer’s Dictionary IT-SC book 110 echo bcmod(15,3);//returns 0 echo bcmod(15,4);//returns

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

Từ khóa liên quan

Mục lục

  • Cover

  • PHP Developer's Dictionary

  • About the Authors

  • Acknowledgments

    • Tell Us What You Think!

    • Introduction

      • Who Should Buy This Book?

      • Organization of the Chapters

      • Writing Conventions

      • Chapter 1. Basic PHP Background and History

        • Advantages of PHP 4

        • Installation

          • PHP Installation General Overview

          • Configuration Options

          • Types, Variables, and Constants

          • Arrays

          • Strings

          • Type Conversion

          • Variables

          • Constants

          • Operators and Mathematical Functions

            • Expressions and Operators

            • Control Structures

            • Mathematical Functions

            • Functions, Classes, and Objects

              • Functions

Tài liệu cùng người dùng

Tài liệu liên quan