diff --git a/reference/array/functions/array-map.xml b/reference/array/functions/array-map.xml index cc54c1fa28..9ef72c0738 100644 --- a/reference/array/functions/array-map.xml +++ b/reference/array/functions/array-map.xml @@ -22,7 +22,9 @@ used as arguments for the callback. The number of parameters that the callback function accepts should match the number of arrays - passed to array_map. + passed to array_map. Excess + input arrays are ignored. An ArgumentCountError + is thrown if an insufficient number of arguments is provided. @@ -122,11 +124,16 @@ Array $value * 2, range(1, 5))); + ?> ]]> @@ -150,12 +157,12 @@ Array $m]; } @@ -371,6 +378,44 @@ array(1) { string(5) "value" } } +]]> + + + + <function>array_map</function> - associative arrays + + While array_map does not directly support + using the array key as an input, that may be simulated using array_keys. + + + 'First release', + 'v2' => 'Second release', + 'v3' => 'Third release', +]; + +// Note: Before 7.4.0, use the longer syntax for anonymous functions instead. +$callback = fn(string $k, string $v): string => "$k was the $v"; + +$result = array_map($callback, array_keys($arr), array_values($arr)); + +var_dump($result); +?> +]]> + + &example.outputs; + + + string(24) "v1 was the First release" + [1]=> + string(25) "v2 was the Second release" + [2]=> + string(24) "v3 was the Third release" +} ]]>