How to use the PHP function count () to find the length of the array _ PHP Tutorial

Source: Internet
Author: User
How to use the PHP function count () to obtain the length of the array. Intcount (mixedvar) returns the number of units in var, usually an array (only one unit for any other type ). If var is not an array type, 1 is returned.Int count (mixed var)

Returns the number of units in var, usually an array (only one unit is available for any other type ).

If var is not of the array type, the result of 1 (exception: count (NULL) is 0) is returned ).

Warning

The PHP function count () returns 0 for uninitialized variables, but 0 for empty arrays. Use isset () to test whether the variable has been initialized.

Example 1. count () example

 
 
  1. php
  2. $vegetables[0] = "corn";
  3. $vegetables[1] = "broccoli";
  4. $vegetables[2] = "zucchini";
  5. $text = implode(",", $vegetables);
  6. echo $text;
  7. ?>

Sometimes, if you do not know the PHP function count (), use the stupid method: select count (*) from table


Counts int count (mixed var) returns the number of units in var, usually an array (only one unit for any other type ). If var is not an array type, 1 is returned (...

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.