PHP array_shift() Function6 Jan 2025 | 1 min read The array_shift() function is an inbuilt function of PHP. The array_shift( ) function is used to remove the first element from an array, and returns the value of the removed element. This function was introduced in PHP 4.0. SyntaxParameter
Return typeThe array_shift( ) function returns the value of the removed element from an array. If the array is empty, it will return NULL. Important note: If the keys are numeric, all elements will get new keys, starting from 0 and increases by 1.Example 1Output: testArray ( [0] => one day [1] => t20 ) Example 2Output: Array ( [0] => math [1] =>english [2] =>hindi ) Science Example 3Output: 200Array ( [sehwag] => 400 [ganguly] => 500 [yuvraj] => 100 ) Example 4Output: TCSArray ( [0] => Infosys [1] =>Mindtree ) Next TopicPhp-array-shuffle-function |
The array_slice() function is an inbuilt function of PHP. The array_slice() function is used to extract a slice of an array. This function was introduced in 4.0. Syntax array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]]...
1 min read
PHP array_fill( ) Function The array_fill( ) function is used to fill an array with values. This function creates a user-defined array with a given pre-filled value. It was introduced in PHP 4. Syntax array array_fill ( int $start_index , int $num , mixed $value ) Parameter Parameter Description Is compulsory starting_index The first...
1 min read
PHP ksort() Function The PHP ksort() sorts an associative array in ascending order, according to the key. It is mainly used for an associative array. This function was introduced in PHP 4.0. Syntax bool ksort ( array &$array [, int $sort_flags = SORT_REGULAR ] ); Parameter Parameter Description Is compulsory array Specifies the array...
1 min read
The array_filter( ) function filters the values of an array using a callback function. This function passes each value of the input array to the callback function. If the callback function returns true, the current value from the input is returned into the result array....
2 min read
The array_multisort() is an built-in function in PHP. This function is used to sort multiple arrays at once or a multi-dimensional array with each dimension. This function was introduced in PHP 4.0. Syntax bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed$array1_sort_flags = SORT_REGULAR...
2 min read
The array_rand()function is a inbuilt function in PHP. The array_rand()function is used to fetch one or more random entries from an array. It uses a pseudo-random number generator that is not suitable for cryptographic purposes. This function was introduced in PHP 4.0. Syntax mixed array_rand ( array...
1 min read
The count( ) function is an inbuilt function of PHP, and it is used to count the elements of an array or the properties of an object. This function was introduced in PHP 4.0. Syntax int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] ); Parameters Parameter Description Is...
1 min read
PHP reset() Function The PHP reset( ) function is used to move the array's internal pointer to the first element. This function was introduced in PHP 4.0. Syntax mixed reset ( array &$array ); Parameter Parameter Description Is compulsory array Specifies the array to use. compulsory Returns The reset( ) function returns the value of the first...
1 min read
PHP natsort() Function The PHP natsort( ) function is used to sort an array using a "natural order" algorithm. The natsort( ) function implements a sort algorithm but maintains original keys and values. This function was introduced in PHP 4.0. Syntax bool natsort ( array &$array ); Parameter Parameter Description Is compulsory array Specifies...
2 min read
The array_splice() function is an extended version of array_slice() function. The array_splice() function removes selected elements from an array and replaces it with new elements. This function was introduced in PHP 4. Syntax arrayarray_splice ( array &$input , int $offset [, int $length = count($input) [, mixed...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India