# PHP - Array count() Function

The PHP Array count() function returns the number of elements present in the given array.

### Syntax

```count(array, mode)
```

### Parameters

 `array` `Required. ` Specify an array. `count` `Optional. `Specify the mode. There are two possible values: 0 - Default - Does not count all elements of multidimensional arrays. 1 or COUNT_RECURSIVE - Counts the elements recursively (counts all the elements of multidimensional arrays).

### Return Value

Returns the number of elements in the array. If the parameter is neither an array nor an object with implemented Countable interface, 1 is returned. If the parameter is null, 0 is returned.

### Exceptions

throws E_WARNING, if the array contains itself more than once.

### Example:

The example below shows the usage of count() function.

```<?php
\$Arr = array(10, 20, 30, 40, 50);

//counting the number of elements in the array
\$x = count(\$Arr);

echo "Number of elements in Arr: \$x";
?>
```

The output of the above code will be:

```Number of elements in Arr: 5
```

### Example:

The example below shows the usage of count() function with an associative array.

```<?php
\$Arr = array("Marry"=>25, "John"=>30, "Jo"=>45, "Kim"=>22);

//counting the number of elements in the array
\$x = count(\$Arr);

echo "Number of elements in Arr: \$x";
?>
```

The output of the above code will be:

```Number of elements in Arr: 4
```

❮ PHP Array functions

5
{"ft_lang_label":"__label__en","ft_lang_prob":0.5489371,"math_prob":0.94578725,"size":1163,"snap":"2021-31-2021-39","text_gpt3_token_len":293,"char_repetition_ratio":0.18032786,"word_repetition_ratio":0.35416666,"special_character_ratio":0.27515048,"punctuation_ratio":0.17372881,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9925908,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-29T00:05:33Z\",\"WARC-Record-ID\":\"<urn:uuid:1c2d2497-44dc-44b3-9421-0502d47b6112>\",\"Content-Length\":\"19757\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4a20e58b-dc7a-4443-a3b1-4985ad12b0b8>\",\"WARC-Concurrent-To\":\"<urn:uuid:6cc836fa-f1ce-4812-a895-803125a131ce>\",\"WARC-IP-Address\":\"34.66.60.131\",\"WARC-Target-URI\":\"https://www.alphacodingskills.com/php/notes/php-array-count.php\",\"WARC-Payload-Digest\":\"sha1:W2OETYHE6WC6GRD4FUJMR5XSK525TDY3\",\"WARC-Block-Digest\":\"sha1:7QOSBOL7TG7XIBJZ2LJM5MWPR3P4LULP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153803.69_warc_CC-MAIN-20210728220634-20210729010634-00370.warc.gz\"}"}