[Single topic] which of the following functions is used to remove the number of elements of the PHP array

Source: Internet
Author: User

  1. Array_reverse
  2. min
  3. Count
  4. Max

Answer C

Instance

Returns an array in the reverse order of elements:

<?php$a=array ("A" = "Volvo", "B" and "BMW", "c" = "Toyota");p Rint_r ( array_reverse($a) ); >

Running an instance

Definition and usage

The Array_reverse () function returns an array in the reverse order of elements.

Description

The Array_reverse () function flips the order of elements in the original array, creates a new array, and returns.

If the second parameter is specified as true, the key name of the element remains unchanged or the key names are lost.

Grammar
Array_reverse (array,preserve)
Parameters Description
Array Necessary. Specifies the array.
Preserve

Optional. Specifies whether the key name of the original array is preserved.

This parameter is newly added in PHP 4.0.3.

Possible values:

  • True
  • False
Technical details
return value: Returns the inverted array.
PHP version: 4 +
Update log: Added the preserve parameter in PHP 4.0.3.
More examples of examples 1

Returns the original array, reverses the array, and retains the inverted array of the original array key names:

<?php$a=array ("Volvo", "XC90", Array ("BMW", "Toyota")), $reverse =array_reverse ($a), $preserve = array_reverse($a,true) ;p rint_r ($a); Print_r ($reverse);p rint_r ($preserve);? >

Running an instance

Definition and usage

MIN () returns the minimum value.

Grammar
Min (x, y)
Parameters Description
X Necessary. A number.
Y Necessary. A number.
Description

MIN () returns the smallest value in the parameter.

If there is only one parameter and an array, min () returns the smallest value in the array. If the first argument is an integer, a string, or a floating-point number, then at least two parameters are required and min () returns the smallest of these values. You can compare an unlimited number of values.

Hints and Notes

Note: PHP treats a non-numeric string as 0, but if this is the smallest value, it will still return a string. If more than one parameter evaluates to 0 and is the Minimum, min () returns the string with the lowest alphabetical order, or 0 if there are no strings.

Example

In this example, we will use min () to return the minimum value from two specified numbers:

<?phpecho (min (5,7)), Echo (min ( -3,5)), Echo (min ( -3,-5)), Echo (min (7.25,7.30)); >

The output is similar to:

5-3-57.25

Instance

Returns the number of elements in the array:

count($cars);? >

Running an instance

Definition and usage

The count () function returns the number of elements in the array.

Grammar
COUNT (array,mode);
Parameters Description
Array Necessary. Specifies the array.
Mode

Optional. prescribed mode. Possible values:

  • 0-Default. Do not count all elements in a multidimensional array
  • 1-counts the number of elements in the array recursively (computes all elements in a multidimensional array)
Description

The count () function calculates the number of cells in an array or the number of properties in an object.

For an array, returns the number of its elements, and returns 1 for other values. Returns 0 if the argument is a variable and the variable is not defined.

If mode is set to Count_recursive (or 1), the number of elements in the array in the multidimensional array is recursively computed.

Technical details
return value: Returns the number of elements in the array.
PHP version: 4 +
Update log: The mode parameter is added in PHP 4.2.
More examples of examples 1

To count recursively on an array:

<?php$cars=array  ("  Volvo" =>array  ("  XC60",  "XC90"  ),  "BMW" =>array  ( "  X3",  "X5"  ),  "Toyota" =>array  (  "Highlander"  )  count($cars)."<br>" count($cars,1) ; >

Definition and usage

Max () returns the maximum value.

Grammar
Max (x, y)
Parameters Description
X Necessary. A number.
Y Necessary. A number.
Description

Max () returns the value with the largest number in the parameter.

If there is only one parameter and an array, Max () returns the largest value in the array. If the first argument is an integer, a string, or a floating-point number, then at least two parameters are required and Max () returns the largest of these values. You can compare an unlimited number of values.

Hints and Notes

Note: PHP treats non-numeric strings as 0, but if this is the maximum value, it will still return a string. If more than one parameter evaluates to 0 and is the maximum, max () returns 0 of the value, and if there is no value of 0 in the argument, the string that is the largest in alphabetical order is returned.

Example

In this example, we will use Max () to return the maximum value in two specified numbers:

<?phpecho (Max (5,7)), Echo (Max ( -3,5)), Echo (Max ( -3,-5)), Echo (Max (7.25,7.30)); >

The output is similar to:

75-37.3

[Single topic] which of the following functions is used to remove the number of elements of the PHP 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: 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.