Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

count(3) [php man page]

COUNT(3)								 1								  COUNT(3)

count - Count all elements in an array, or something in an object

SYNOPSIS
int count (mixed $array_or_countable, [int $mode = COUNT_NORMAL]) DESCRIPTION
Counts all elements in an array, or something in an object. For objects, if you have SPL installed, you can hook into count(3) by implementing interface Countable. The interface has exactly one method, Countable::count, which returns the return value for the count(3) function. Please see the Array section of the manual for a detailed explanation of how arrays are implemented and used in PHP. PARAMETERS
o $array_or_countable - An array or Countable object. o $mode - If the optional $mode parameter is set to COUNT_RECURSIVE (or 1), count(3) will recursively count the array. This is particu- larly useful for counting all the elements of a multidimensional array. Caution count(3) can detect recursion to avoid an infinite loop, but will emit an E_WARNING every time it does (in case the array contains itself more than once) and return a count higher than may be expected. RETURN VALUES
Returns the number of elements in $array_or_countable. If the parameter is not an array or not an object with implemented Countable inter- face, 1 will be returned. There is one exception, if $array_or_countable is NULL, 0 will be returned. Caution count(3) may return 0 for a variable that isn't set, but it may also return 0 for a variable that has been initialized with an empty array. Use isset(3) to test if a variable is set. EXAMPLES
Example #1 count(3) example <?php $a[0] = 1; $a[1] = 3; $a[2] = 5; $result = count($a); // $result == 3 $b[0] = 7; $b[5] = 9; $b[10] = 11; $result = count($b); // $result == 3 $result = count(null); // $result == 0 $result = count(false); // $result == 1 ?> Example #2 Recursive count(3) example <?php $food = array('fruits' => array('orange', 'banana', 'apple'), 'veggie' => array('carrot', 'collard', 'pea')); // recursive count echo count($food, COUNT_RECURSIVE); // output 8 // normal count echo count($food); // output 2 ?> SEE ALSO
is_array(3), isset(3), strlen(3). PHP Documentation Group COUNT(3)

Check Out this Related Man Page

xpc_array_create(3)					   BSD Library Functions Manual 				       xpc_array_create(3)

NAME
xpc_array_create -- creation and management of XPC arrays SYNOPSIS
#include <xpc/xpc.h> xpc_object_t xpc_array_create(const xpc_object_t *objects, size_t count); void xpc_array_set_value(xpc_object_t array, size_t index, xpc_object_t value); void xpc_array_append_value(xpc_object_t array, xpc_object_t value); xpc_object_t xpc_array_get_value(xpc_object_t array, size_t index); size_t xpc_array_get_count(xpc_object_t array); bool xpc_array_apply(xpc_object_t array, xpc_array_applier_t applier); void xpc_array_set_bool(xpc_object_t array, size_t index, bool value); void xpc_array_set_int64(xpc_object_t array, size_t index, int64_t value); void xpc_array_set_uint64(xpc_object_t array, size_t index, uint64_t value); void xpc_array_set_double(xpc_object_t array, size_t index, double value); void xpc_array_set_date(xpc_object_t array, size_t index, int64_t value); void xpc_array_set_data(xpc_object_t array, size_t index, const void *bytes, size_t length); void xpc_array_set_string(xpc_object_t array, size_t index, const char *value); void xpc_array_set_uuid(xpc_object_t array, size_t index, const uuid_t value); void xpc_array_set_fd(xpc_object_t array, size_t index, int value); void xpc_array_set_connection(xpc_object_t array, size_t index, xpc_connection_t value); bool xpc_array_get_bool(xpc_object_t array, size_t index); int64_t xpc_array_get_int64(xpc_object_t array, size_t index); uint64_t xpc_array_get_uint64(xpc_object_t array, size_t index); double xpc_array_get_double(xpc_object_t array, size_t index); int64_t xpc_array_get_date(xpc_object_t array, size_t index); const void * xpc_array_get_data(xpc_object_t array, size_t index, size_t *length); const uint8_t * xpc_array_get_uuid(xpc_object_t array, size_t index); const char * xpc_array_get_string(xpc_object_t array, size_t index); int xpc_array_get_fd(xpc_object_t array, size_t index); xpc_connection_t xpc_array_get_connection(xpc_object_t array, size_t index); ARRAYS
XPC arrays are collections of XPC objects ordered by index. The index is zero-based. XPC arrays are contiguous, and values must exist at all indexes between zero and the greatest index of the array. A hole in the array can be simulated by using a null object as returned by xpc_null_create(3). CREATION
The xpc_array_create() function returns a newly created array. The caller may optionally provide objects, a C array of XPC object references, to initialize the array. The count is used to specify the size of the C array. If objects is NULL, then count must be zero. If count speci- fies more elements than are actually present in values or if values is NULL and count is non-zero, the behavior is undefined. GETTING AND SETTING VALUES
The xpc_array_append_value() function may be used to append a value to the end of an array. This operation increases the count of the values in the array by one. The value of a specific index in the array may be set using the xpc_array_set_value() function. The value must be non-NULL, and the index must already exist (i.e. less than the count provided at creation or extended through previous append operations). The value at a specific index of an array may be retrieved using the xpc_array_get_value() function. The result of getting a non-existing index (i.e. one that was not specified at creation or through a previous append operation) in undefined. PRIMITIVE GET AND SET FUNCTIONS
Various functions exist for retrieving primitive C and operating system types directly from an array without the need for an intermediate boxed object. See xpc_object(3) for more information. The special XPC_ARRAY_APPEND constant may be used to append a value to the end of the array instead of operating on a specific index. SEE ALSO
xpc_object(3), xpc_objects(3), xpc_dictionary_create(3) Darwin 1 July, 2011 Darwin
Man Page