PHP | Ds\Stack count() Function Last Updated : 30 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Stack::count() function is an inbuilt function in PHP which is used to count the number of elements present in the Stack. Syntax: int Ds\Stack::count( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the number of elements present in the Stack. Below programs illustrate the Ds\Stack::count() function in PHP: Program 1: php <?php // Declare new stack $stack = new \Ds\Stack([10, 15, 21]); // Display the stack element var_dump($stack); // Count number of elements // present in the stack echo "Number of elements present in the stack: "; print_r($stack->count()); ?> Output: object(Ds\Stack)#1 (3) { [0]=> int(21) [1]=> int(15) [2]=> int(10) } Number of elements present in the stack: 3 Program 2: php <?php // Declare new stack $stack = new \Ds\Stack(["Geeks", "for", "Keegs"]); // Display the stack element print_r($stack); // Display count of elements // present in the stack echo "Number of elements present in the stack: "; var_dump($stack->count()); ?> Output: Ds\Stack Object ( [0] => Keegs [1] => for [2] => Geeks ) Number of elements present in the stack: int(3) Reference: https://www.php.net/manual/en/ds-stack.count.php Comment More infoAdvertise with us Next Article PHP | Ds\Stack copy() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_stack Similar Reads PHP Ds\Set count() Function The Ds\Set::count() function of Ds\Set class in PHP is an inbuilt function which is used to count the number of values present in the Set. This is also referred to as the size of the Set instance. Syntax: int public Ds\Set::count() Parameters: This function does not accept any parameter. Return Valu 1 min read PHP Ds\Set count() Function The Ds\Set::count() function of Ds\Set class in PHP is an inbuilt function which is used to count the number of values present in the Set. This is also referred to as the size of the Set instance. Syntax: int public Ds\Set::count() Parameters: This function does not accept any parameter. Return Valu 1 min read PHP | Ds\Stack copy() Function The Ds\Stack::copy() function of PHP Ds\Stack class is used to create a shallow copy of the original stack and returns the copied stack. Syntax: Ds\Stack public Ds\Stack::copy ( void ) Parameters: This function does not accept any parameters.Return Value: This function returns a shallow copy of the 1 min read PHP | Ds\Stack copy() Function The Ds\Stack::copy() function of PHP Ds\Stack class is used to create a shallow copy of the original stack and returns the copied stack. Syntax: Ds\Stack public Ds\Stack::copy ( void ) Parameters: This function does not accept any parameters.Return Value: This function returns a shallow copy of the 1 min read PHP | Ds\Stack clear() Function The Ds\Stack::clear() function of PHP is used to remove all elements from a Stack and clear it. This function simply removes all of the elements from the Stack but not completely deletes it. It just empties it. Syntax: void public Ds\Stack::clear ( void ) Parameters: This function does not accept an 2 min read PHP | Ds\Stack clear() Function The Ds\Stack::clear() function of PHP is used to remove all elements from a Stack and clear it. This function simply removes all of the elements from the Stack but not completely deletes it. It just empties it. Syntax: void public Ds\Stack::clear ( void ) Parameters: This function does not accept an 2 min read Like