Found 35502 Articles for Programming

array_unshift() function in PHP

karthikeya Boyini
Updated on 23-Dec-2019 07:18:50

69 Views

The array_unshift() function adds one or more elements to the beginning of an array.Syntaxarray_unshift(arr, val1, val2, val3)Parametersarr − The specified array. Required.val1 − Value to be inserted. Required.val2 − Value to be inserted. Optional.val3 − Value to be inserted. Optional.ReturnThe array_unshift() function returns the new elements in the array.ExampleThe following is an example − Live DemoOutputThe following is the output −3ExampleLet us see another example − Live DemoOutputThe following is the output −Array ( [0] => three [p] => one [q] => two )

array_uintersect_uassoc() function in PHP

Samual Sam
Updated on 24-Jun-2020 12:28:08

15 Views

The array_uintersect_unassoc() function compares array keys and array values in user-made functions, and returns an arraySyntaxarray_uintersect_uassoc(arr1, arr2, arr3, … , compare_func1, compare_func2)Parametersarr1 − The first array to compare from.arr2 − The second array to be compared with.arr3 − More arrays to compare.compare_func1 − The comparison function that compares the array keys. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.compare_func2 − The comparison function that compares the array values. It must return an integer less than, equal to, ... Read More

array_uintersect() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 12:28:27

39 Views

The array_uintersect() function compares array values in a user-made function and returns an array. It returns an array containing all the values of the first array that are not present in any of the other parameters.Syntaxarray_uintersect(arr1, arr2, arr3, … , compare_func)Parametersarr1 − The first array to compare from.arr2 − The second array to be compared with.arr3 − More arrays to compare.compare_func − The comparison function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.ReturnThe array_uintersect() function returns an ... Read More

array_udiff_assoc() function in PHP

Samual Sam
Updated on 24-Jun-2020 12:28:52

28 Views

The array_udiff_assoc() function compares array keys, and compares array values in a user-made function, and returns an array. It returns an array containing all the values of the first array that are not present in any of the other parameters.Syntaxarray_udiff_assoc(arr1, arr2, arr3, … , compare_func)Parametersarr1 − The first array to compare from.arr2 − The second array to be compared with.arr3 − More arrays to compare.compare_func − The comparison function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.ReturnThe ... Read More

array_sum() function in PHP

karthikeya Boyini
Updated on 23-Dec-2019 07:34:32

6K+ Views

The array_sum() function returns the sum of the values in an array. The returned value can be integer or float. It returns 0 if the array is empty.Syntaxarray_sum(arr)Parametersarr − the specified arrayReturnThe array_sum() function returns the sum of values. The returned value can be integer or float. It returns 0 if the array is empty.ExampleThe following is an example − Live DemoOutputThe following is the output −600ExampleLet us see another example − Live DemoOutputThe following is the output −96.2

array_slice() function in PHP

Samual Sam
Updated on 23-Dec-2019 07:32:01

275 Views

The array_slice() function returns selected parts of an array.Syntaxarray_slice(arr, begin, length, preserve)Parametersarr − The specified arraybegin − The beginning of the array where the slicing will take place. It shows the position in the array. If begin is negative (-1), then the slicing begins from the end of the array. The value -2 means begin at the second last element of the array.length − The length of the returned array. If the length is negative then the slicing will stop that many elements from the end of the array.preserve − Possible values are TRUE or FALSE. Here, set whether the ... Read More

array_search() function in PHP

karthikeya Boyini
Updated on 13-Sep-2023 14:04:38

26K+ Views

The array_search() function searches an array for a given value and returns the key. The function returns the key for val if it is found in the array. It returns FALSE if it is not found. If val is found in the array arr more than once, then the first matching key is returned.Syntaxarray_search(val, arr, strict)Parametersval − The value to be searchedarr − The array to be searchedstrict − Possible values are TRUE or FALSE. Search for identical elements in the array, set to TRUE.ReturnThe array_search() function returns the key for val if it is found in the array. It ... Read More

array_reduce() function in PHP

Samual Sam
Updated on 24-Jun-2020 12:24:54

28 Views

The array_reduce() function returns an array as a string, using a user-defined function.Syntaxarray_reduce(arr, custom_func, initial)Parametersarr − The array. Required.custom_func − The name of the user-defined function. Required.initial − Initial value to be sent to the function. Optional.ReturnThe array_reduce() function returns the resulting value. It returns NULL, if the array is an empty array and initial isn’t passed.ExampleThe following is an example − Live DemoOutputThe following is the output −2 DEMO One DEMO TwoExampleLet us see another example wherein the given array is reduced o the product of all the elements of the array − Live DemoOutputThe following is the output −1250Read More

array_push() function in PHP

karthikeya Boyini
Updated on 23-Dec-2019 07:22:39

82 Views

The array_push() function inserts one or more elements to the end of an array. It returns the new elements pushed into the array.Syntaxarray_push(arr, val1, val2)Parametersarr − The specified arrayval1 − The value to be pushedval2 − The value to be pushedReturnThe array_push() function returns the new elements pushed into the array.ExampleThe following is an example − Live DemoOutputThe following is the output −Array ( [0] => table [1] => chair [2] => pen [3] => pencil [4] => notepad [5] => paperclip )

array_pop() function in PHP

Samual Sam
Updated on 23-Dec-2019 06:56:50

38 Views

The array_pop() function deletes the last element of an array. It returns the value of the last element of the array. If the array is empty, NULL is returned.Syntaxarray_pop(arr)Parametersarr − The specified arrayReturnThe array_pop() function returns the last element of the array. If the array is empty, NULL is returned.The following is an example −Example Live DemoOutputThe following is the output −tablet

Advertisements