Found 1466 Articles for PHP

array_fill_keys() function in PHP

Samual Sam
Updated on 30-Jul-2019 22:30:23

51 Views

The array_fill_keys() function fill an array with values, specifying keys. It returns the filled array. Syntax array_fill_keys(keys, values) Parameters keys − Array of values to be used as keys. values − Values that would be used to fill. Return The array_fill_keys() function returns the filled array. Example Live Demo Output Array ( [p] => demo [q] => demo [r] => demo ) Let us see another example. Example Live Demo Output Array ( [a] => demo [b] => demo [c] => demo [1] => demo [2] => demo [3] => demo [steve] => demo [tom] => demo [4] => demo [5] => demo )

array_fill() function in PHP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

135 Views

The array_fill() function is used to fill an array with values. It returns the filled array. It returns the filled array. Syntax array_fill(start_index, num, value) Parameters start_index − First index of the returned array. Required. num − The count of elements to insert. Required. value − The value that would fill the array. Required. Return The array_fill() function returns the filled array. Example Live Demo Output Array ( [3] => demo [4] => demo [5] => demo [6] => demo [7] => demo )

array_diff_ukey() function in PHP

Samual Sam
Updated on 24-Jun-2020 09:36:59

44 Views

The array_diff_ukey function compares array keys, with an additional user-made function check, and returns the differences.Syntaxarray_diff_ukey(arr1, arr2, arr3, arr4, …, compare_func)Parametersarr1 − Array to compare from. Required.arr2 − Array to compare against. Required.arr3 − You can add more arrays to compare. Optional.arr4 − You can add more arrays to compare. Optional.compare_func − This callback function must return an integer than 0 if the first argument is considered to be respectively than the second.ReturnThe array_diff_ukey() function returns an array containing the entries from the first array that are not present in any of the other arrays.The following is an ... Read More

array_diff_uassoc() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 09:37:17

34 Views

The array_diff_uassoc() compares array keys and values, with an additional user-made function check, and returns the differences. It returns an array containing the entries from the first array that are not present in any of the other arrays.Syntaxarray_diff_uassoc(arr1, arr2, arr3, arr4, …, compare_func)Parametersarr1 − Array to compare from. Required.arr2 − Array to compare against. Required.arr3 − You can add more arrays to compare. Optional.arr4 − You can add more arrays to compare. Optional.compare_func − This callback function must return an integer than 0 if the first argument is considered to be respectively than the second.ReturnThe array_diff_uassoc() function returns ... Read More

array_diff_key() function in PHP

Samual Sam
Updated on 30-Jul-2019 22:30:23

53 Views

The array_diff_key() function compares array keys, and returns the differences. It returns an array containing the entries from the first array that are not present in any of the other arrays. Syntax array_diff_key(arr1, arr2, arr3, arr4, ...) Parameters arr1 − Array to compare from. Required. arr2 − Array to compare against. Required. arr3 − You can add more arrays to compare. Optional. arr4 − You can add more arrays to compare. Optional. Return The array_diff_key() function returns an array containing the entries from the first array that are not present in any of the other arrays. ... Read More

array_diff_assoc() function in PHP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

38 Views

The array_diff_assoc() function compares array keys and values, and returns the differences. The array_diff() function only compares the values, whereas in array_diff_assoc() function both the keys and values are used for comparison. Syntax array_diff_assoc(arr1, arr2, arr3, arr4, …) Parameters arr1 − Array to compare from. Required. arr2 − Array to compare against. Required. arr3 − You can add more arrays to compare. Optional. arr4 − You can add more arrays to compare. Optional. Return The array_diff_assoc() function returns the comparison between both the arrays. It returns an array containing all the values from arr1 that ... Read More

array_diff() function in PHP

Samual Sam
Updated on 30-Jul-2019 22:30:23

46 Views

The array_diff() function compares array values, and returns the differences. It returns an array containing the entries from the first array that are not present in any of the other arrays. Syntax array_diff(arr1, arr2, arr3, arr4, …) Parameters arr1 − Array to compare from. Required. arr2 − Array to compare against. Required. arr3 − You can add more arrays to compare. Optional. arr4 − You can add more arrays to compare. Optional. Return The array_diff() function returns an array containing the entries from the first array that are not present in any of the other ... Read More

array_count_values() function in PHP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

5K+ Views

The array_count_values() function returns an array with the number of occurrences for each value. It returns an associative array. The returned array has keys as the array’s values, whereas values as the count of the passed values. Syntax array_count_values(arr) Parameters arr − The array for which we want to count the values. Return The array_count_values() function returns an associative array. The returned array has keys as the array’s values, whereas values as the count of the passed values. Example Live Demo Output Array ( [Laptop] => 1 [Keyboard] => 4 [Mouse] => 2 )

array_combine() function in PHP

Samual Sam
Updated on 23-Dec-2019 06:40:08

90 Views

The array_combine() function creates an array by using one array for keys and another for its values. It returns the combined array. The function returns FALSE if the number of elements of each array does not match.Syntaxarray_combine(keys, values);Parameterskeys − Array of keys.values − Array of values.ReturnThe array_combine() function returns the combined array. It returns FALSE if the number of elements of each array does not match.The following is an example combining two arrays.Example Live DemoOutputThe following is the output −Array ( [football] => david [cricket] => steve )

array_chunk() function in PHP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

47 Views

The array_chunk() function splits an array into chunks of arrays. It returns a multidimensional numerically indexed array, starting with zero. Syntax array_chunk(arr, chunk_size, preserve_key) Parameters arr − The array chunk_size − The size of chunk in integer preserve_key − It has the following values: TRUE- Keys are preserved, FALSE: The chunk is reindexed. Return The array_chunk() function returns a multidimensional numerically indexed array, starting with zero. The following is an example that shows how an array is split. Example Live Demo Output Array ( [0] => Array ( [Electronics] => 99 [Accessories] => 110 ) [1] => Array ( [Clothing] => 150 [Furniture] => 198 ) )

Advertisements