This functions takes two parameters as an input. First parameter contains an array and second parameter contains a keyword. There are two extra options available to this function. such as – CASE_UPPER and CASE_LOWER.
This function converts an array index in to lowercase/uppercase based on the keyword settings.
– Example of array_change_key_case():
$input = array ( "first" =>1, "second" =>2, "third" =>3, "fourth" =>4 ); print_r(array_change_key_case($input,CASE_UPPER));
This function takes an array as input, and it has additional 2 parameters. First parameters is an array, second parameter is size of chunk and third parameter is a Boolean value which is optional. If third parameter set as true then its chucked array by maintained its indexed value. Otherwise chucked array index always starts from zero(0).
– Example of array_chunk() :
$input_array = array ('a','b','c','d','e'); print_r(array_chunk($input_array,2)); print_r(array_chunk($input_array,2,true));
* This function takes 2 arrays as input. First array element considered as key and second array element considered as value. It’s return an array. It shows an error if any element is empty or number of elements does not matched.
– Example of array_combine() :
$a = array("red","green","yellow"); $b = array("mango","apple","orange"); $c = array_combine($a,$b); print_r($c);
This function takes an array as input. It show the number of occurrence of a value in an array. It return an array.
– Example of array_count_values() :
$input_array = array (1,"hello",1,"world","hello"); $ouput_array = array_count_values($input_array); print_r($ouput_array);
This function takes an array as input. The absolute value of number. If the argument number is of type float, the return type is also float, otherwise it is integer (as float usually has a bigger value range than integer). It return integer value.
– Example of sizeof() function:
$input_array = array ("dog","cat","bird","man","cow"); $array_size = sizeof($input_array); echo "Array size:".$array_size;
6. count() function:
This function takes an array as input. The number of elements in var. If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is null, 0 will be returned. count 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 to test if a variable is set. It return integer value.
– Example of count() function:
$input_array = array ("pink","red","yellow","blue","green"); $array_size = count($input_array); echo "Array size:".$array_size;
That’s all for today. Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!