What is the principle of dealing with array multiplication in array_map?

function myfunction ($v)
{
return ($vested roomv);
}

$a=array (1, 2, 3, 4, 5)

/ *

  • the following direct calls to do array multiplication are prohibited
  • but there is no error through the array_map call

* /
/ / print_r (myfunction ($a);

/ *

  • this call will not report an error. Does anyone know what the principle is?

* /
print_r (array_map ("myfunction", $a));

Php
May.25,2022

array_map


misunderstanding of array_map 's function
array_map traverses every element in the array and then uses the function to do the operation,
instead of calling the function directly.


if you use PHP to implement array_map:

function array_map(callable $callback, array $array):array {
    $result = [];
    $idx = 0;
    foreach($array as $row) {
        $result[] = $callback($row, $idx);
        $idxPP;
    }
    return $result;
}
Menu