Found 1466 Articles for PHP

array_map() function in PHP

Samual Sam
Updated on 24-Jun-2020 09:38:18

70 Views

The array_map() function sends each value of an array to a user-made function, which returns new values.Syntaxarray_map(callback, arr1, arr2 −, arr3 −, arr4 −, …)Parameterscallback− The callback functionarr1 − The array to be modifiedarr2 − The array to be modifiedarr3 − The array to be modifiedReturnThe array_map() function returns an array containing the values of the first array, after applying the user-made function to each one.Example Live DemoOutputArray ( [0] => 1 [1] => 4 [2] => 9 )ExampleLet us see another example to create array of arrays using array_map(). Live DemoOutputArray ( [0] => Array ( [0] => 1 [1] => steve [2] => cricket ) [1] => Array ( [0] => 2 [1] => david [2] => football ) [2] => Array ( [0] => 3 [1] => nadal [2] => tennis ) )

array_keys() function in PHP

karthikeya Boyini
Updated on 23-Dec-2019 07:05:09

202 Views

The array_keys() function returns all the keys of an array. It returns an array of all the keys in array.Syntaxarray_keys(arr, value, strict)Parametersarr − The array from which the keys will be returnedvalue − If the values are specified, then only the keys containing these values will be returned.strict − Determines if strict comparison (===) should be used during the search.ReturnThe array_keys() function returns an array of all the keys in array.Example Live DemoOutputArray ( [0] => one [1] => two [2] => three [3] => four )ExampleLet us see another example wherein we will find the key for a specific value ... Read More

array_key_exists() function in PHP

Samual Sam
Updated on 24-Jun-2020 09:38:49

87 Views

The array_key_exists() function checks if the specified key exists in the array. The function returns true if the key exists and false if the key does not exist.Syntaxarray_key_exists(key, arr)Parameterskey − Specify the key to be checked.arr − The array wherein we will find the key.ReturnThe array_key_exists() function returns true if the key exists and false if the key does not exist.Example Live DemoOutputKey is in the array!

array_intersect_ukey() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 09:39:15

31 Views

The array_intersect_ukey() function compares array keys, with an additional user-made function check, and returns the matches. The function returns an array containing the entries from the first array that are present in all of the other arrays.Syntaxarray_intersect_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_intersect_ukey() function returns an ... Read More

array_intersect_uassoc() function in PHP

Samual Sam
Updated on 24-Jun-2020 09:39:33

46 Views

The array_intersect_unassoc() function compares array keys and values, with an additional user-made function check, and returns the matches.Syntaxarray_intersect_unassoc(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_intersect_uassoc() function returns an array containing the entries from the first array that are not present in any of the other arrays.Example Live DemoOutputArray ... Read More

array_intersect_key() function in PHP

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

65 Views

The array_intersect_key() function compares array keys, and returns the matches. It returns an array containing all of the values in the first array whose values exist in all of the parameters. Syntax array_intersect_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_intersect_key() function returns an array containing all of the values in the first array whose values exist in all of the ... Read More

array_intersect_assoc() function in PHP

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

35 Views

The array_intersect_assoc() function compares array values, and returns the matches. Syntax array_intersect_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_intersect_assoc() function returns an array containing all of the values in the first array whose values exist in all of the parameters. Example Live Demo Output Array ( [p] => headphone [q] => earpod )

array_intersect() function in PHP

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

53 Views

The array_intersect() function compares array values, and returns the matches. It returns an array containing all of the values in the first array whose values exist in all of the parameters. Syntax array_intersect(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_intersect() function returns an array containing all of the values in the first array whose values exist in all of the ... Read More

array_flip() function in PHP

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

85 Views

The array_flip() function exchanges all keys with their associated values in an array. It returns flipped array on success, else NULL on failure. Syntax array_flip(arr) Parameters arr − Specify the array of key/value pairs to be flipped. Return The array_flip() function returns flipped array on success, else NULL on failure. Example Live Demo Output Array ( [keyboard] => p [mouse] => q [monitor] => r )

array_filter() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 09:36:12

76 Views

The array_filter() function filters elements of an array using a user-made callback function. It returns the filtered array.Syntaxarray_filter(arr, callback, flag)Parametersarr − The array that will be filteredcallback − The callback function to be usedflag − The parameters sent to the callback function:ARRAY_FILTER_USE_KEY − pass key as the only argument to callback instead of the valueARRAY_FILTER_USE_BOTH − pass both value and key as arguments to callback instead of the valueReturnThe array_filter() function returns the filtered array.Example Live DemoOutputArray ( [1] => 6 [4] => 20 [5] => 30 [7] => 48 [9] => 66 )

Advertisements