Home >Backend Development >PHP Tutorial >How to get the length of an array (number of elements) in php

How to get the length of an array (number of elements) in php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:55:521134browse
  1. $users = array ("qdv.cn", "haotu.net", "sharejs.com", "google.com");
  2. print count($users)-1;
Copy code

Example 2, usage of php function count to get the length of an array.

Example 2, the count function is used to obtain the length of the array

  1. $array = array("PHP", "Perl", "Java");
  2. print_r("Size 1: ".count($array)."n");
  3. $array = array();
  4. print_r("Size 2: ".count($array)."n");
  5. ?>
Copy code

Output result: Size 1: 3 Size 2: 0



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn