PHP ksort() Function6 Jan 2025 | 1 min read 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. SyntaxParameter
ReturnsThe ksort() function returns true on success and false on failure. Example 1Output: Array ( [ganguly] => 46 [sachin] => 45 [virat] => 29 ) Example 2Output: Array ( [a] => cricket [b] => hockey [c] => football [d] => badminton ) Example 3Output: Array ( [china] =>beijing [france] =>paris [india] =>newdelhi [russia] =>moscow [united kingdom] =>london ) Example 4Output: Array ( [z] => ruby [y] => java [x] => html ) Next TopicPhp-array-list-function |
PHP uksort() Function The PHP uksort( ) function is used to sort an array by the elements keys using a user-defined comparison function. This function was introduced in PHP 4.0. Syntax bool uksort ( array &$array , callable $key_compare_func ); Parameter Parameter Description Is compulsory array Specifies the array to be sorted. compulsory user_defined_function This function is...
2 min read
The array_keys() function is used to get all the keys or a subset of the keys of an array. It returns the keys, numeric and string, from the input array. This function was introduced in PHP 4.0. Syntax array_keys(array1,value,strict); Parameter Parameter Description Is compulsory array Specifies an array. compulsory search_value Specify a value, then only the...
1 min read
The array_merge( ) function is a built-in function of PHP. This function is used to merge the elements or values of two or more arrays together into a single array. This function was introduced in PHP 4.0. Syntax array array_merge(array $array1[, array $...]); Parameter Parameter Description Is compulsory array1 Specifies an array. compulsory array2 Specifies an...
1 min read
PHP array_unique( ) Function The array_unique( ) function is an inbuilt function of PHP and it is used to remove duplicate values from an array. This function was introduced in 4.0.1 Syntax array array_unique ( array $array [, int $sort_flags = SORT_STRING ] ); Parameters Parameter Description Is compulsory array1 The input array. compulsory sort_flags The optional...
1 min read
The array_search() function is an inbuilt function of PHP. It is used to search the array against the given value. The function returns the first corresponding key if successful. This function was introduced in PHP 4.0.5. Syntax mixed array_search ( mixed $needle , array $haystack [, bool...
1 min read
PHP array_count_values() Function The array_count_values() function returns an array where the keys are the original array's values, and the values is the number of occurrences. In other words, we can say that array_count_values() function is used to calculate the frequency of all of the elements of...
1 min read
The array_push() function is a inbuilt function in PHP. The array_push() function is used to add one or more elements onto the end of an array. The length of array increases by the number of variables pushed. The array_push() function was introduced in PHP 4.0. Syntax int...
1 min read
The array_intersect( ) function is used to Computes the intersection of arrays. It compares two or more arrays and returns an array containing all the values of the first array that are present in other arrays. In this operation, keys are preserved. This function was...
1 min read
PHP pos() Function The PHP pos( ) function is used to fetch the value of the current element in an array. The PHP pos( ) function is an alias of current( ) function. This function was introduced in PHP 4.0. Syntax pos($array); Parameter Parameter Description Is compulsory array Specifies the array to use. compulsory Returns The pos(...
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. Syntax mixed array_shift ( array &$array ); Parameter Parameter Description Is compulsory array name The...
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