如何将数组映射到php

时间:2018-02-24 05:17:00

标签: php arrays

我对数组很困惑。任何人都可以帮我解决这个问题吗? 我有4个阵列,这些都是相关的。

我的数组结构如下:

Array 1:
Array ( [0] => 1 [1] => 2 [2] => 1 [3] => 1 [4] => 2 [5] => 1 )
Array 2:
Array ( [0] => 500 [1] => 500 [2] => 1 [3] => 2 [4] => 3 [5] => 3 )
Array 3:
Array ( [0] => 2 [1] => 2 [2] => 1 [3] => 1 [4] => 2 [5] => 1 )
Array 4:
Array ( [0] => 1 [1] => 2 [2] => 1 [3] => 1 [4] => 2 [5] => 1 )

我必须将数组1中的所有1个值映射到另一个数组。

1 个答案:

答案 0 :(得分:1)

如果要将4个数组的值映射到每个位置,您可以:

 protected void Application_BeginRequest(Object sender, EventArgs e) // Customizing / Intializing DateTime Format to yyyy/MM/dd to avoid conflicts 
    {
        CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
        newCulture.DateTimeFormat.ShortDatePattern = "yyyy/MM/dd";
        newCulture.DateTimeFormat.DateSeparator = "/";
        Thread.CurrentThread.CurrentCulture = newCulture;
    }

这将导致:

$arr1 = array(1, 2, 1, 1, 2, 1 );
$arr2 = array(500, 500, 1, 2, 3, 3 );
$arr3 = array(2, 2, 1, 1, 2, 1 );
$arr4 = array(1, 2, 1, 1, 2, 1 );

$results = array_map(function($v1, $v2, $v3, $v4) {
    return array($v1, $v2, $v3, $v4);
}, $arr1, $arr2, $arr3, $arr4);

echo "<pre>";
print_r( $results );
echo "</pre>";

Doc:http://php.net/manual/en/function.array-map.php