我有 2 个数组 ($numbers
和$letters
),我想创建一个新数组,该数组基于将 every$numbers
与 every结合在一起的函数$letters
。该函数的参数包含$numbers
和的值$letters
。(注意:$numbers 和 $letters 没有相同数量的值)。我需要这样的东西:
$numbers = array(1,2,3,4,5,6,...);
$letters = array('a','b','c','d','e',...);
function myFunction($x,$y){
// $output = some code that use $x and $y
return $output;
};
$array_1 = array( (myFunction($numbers[0],$letters[0])), (myFunction($numbers[0],$letters[1])), myFunction($numbers[0],$letters[2]), myFunction($numbers[0],$letters[3]), etc);
$array_2 = array( (myFunction($numbers[1],$letters[0])), (myFunction($numbers[1],$letters[1])), myFunction($numbers[1],$letters[2]), myFunction($numbers[1],$letters[3]), etc);
$array_3 = array( (myFunction($numbers[2],$letters[0])), (myFunction($numbers[2],$letters[1])), myFunction($numbers[2],$letters[2]), myFunction($numbers[2],$letters[3]), etc);
...
$array_N = array( (myFunction($numbers[N],$letters[0])), (myFunction($numbers[N],$letters[1])), myFunction($numbers[N],$letters[2]), myFunction($numbers[N],$letters[3]), etc);
$array = array($array_1, $array_2, $array_3, etc.);
我知道这可能有效,但它有很多代码,特别是如果我为每个数组有很多值。有没有办法用更少的代码获得相同的结果?我试过这个,但它不工作:
$array = array_map("myFunction($value, $letters)",$numbers));
任何帮助将不胜感激!