合并多个阵列(),这取决于循环和数量 [英] Merge multiple Array() depending loop and number

查看:149
本文介绍了合并多个阵列(),这取决于循环和数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要合并3数组。

我的第一个是:

 阵列([0] =>叶-19 [1] =>班次-1 [2] =>班次-1 [3] =>班次-1 [4] =>位移-1 [5] =>位移-1 [6] =>叶片-19 [7] =>叶片-19 [8] =>位移-1- [9] = GT ;班次-1 [10] =>班次-1 [11] =>班次-1 [12] =>班次-1 [13] =>叶-19 [14] =>叶-19 [ 15] =>位移-1 [16] =>位移-1 [17] =>位移-1 [18] =>位移-1 [19] =>位移-1 [20] =>叶-19 [21] =>叶-19 [22] =>班次-1 [23] =>班次-1 [24] =>班次-1 [25] =>班次-1 [26 ] =>班次-1 [27] ​​=>叶-19 [28] =>叶-19 [29] =>班次-1 [30] =>班次-1 [31] =>班次-1 [32] =>班次-1 [33] =>班次-1 [34] =>叶-19 [35] =>叶-19 [36] =>班次-1 [37] = GT;班次-1 [38] =>班次-1 [39] =>班次-1 [40] =>班次-1 [41] =>叶-19)

我的第二个是:

 阵列([0] => 2013年4月28日[1] => 2013年4月29日[2] => 2013年4月30日[3] => 2013年5月1日[4] => 2013年5月2日[5] => 2013年5月3日[6] => 2013年5月4日)

第三个是:

 阵列([0] => 13 [1] =→10 [2] => 12 [3] => 9 [4] => 14 [ 5] => 11)

我想:


  • 2013年4月28日/ 13 /叶-19

  • 2013年4月29日/ 13 /班次-1

  • 2013年4月30日/ 13 /班次-1

  • 2013年5月1日/ 13 /班次-1

  • 2013年5月2日/ 13 /班次-1

  • 2013年5月3日/ 13 /班次-1

  • 2013年5月4日/ 13 /叶-19

  • 2013年4月28日/ 10 /叶-19

  • 2013年4月29日/ 10 /班次-1

  • 2013年4月30日/ 10 /班次-1

  • 2013年5月1日/ 10 /班次-1

  • 2013年5月2日/ 10 /班次-1

  • 2013年5月3日/ 10 /班次-1

  • 2013年5月4日/ 10 /叶-19

  • ...

Thansk寻求帮助。


什么我trye​​d:

 回声的print_r($ _ POST ['dayType'])<小时/>中。
回声的print_r($ _ POST ['dayArr'])。<小时/>中;
回声的print_r($ _ POST ['userArr'])。<小时/>中;//回声计数($ _ POST ['dayType'])---.Count之间($ _ POST ['dayArr'])---.Count之间($ _ POST ['userArr']);// 2013年5月4日/ 13 /叶-19
$ loopNb1 =计数($ _ POST ['dayType']);
$ loopNb2 =计数($ _ POST ['dayType'])/ 7;为($ A = 0; $ A< $ loopNb1; $一个++){
    回声$ _ POST ['dayType'] [$一]< BR />中。
}回声<小时/>中;为($ B = 0; $ B< $ loopNb2; $ B ++){
    回声$ _POST ['userArr'] [1]。&所述峰; br />中;
}


解决方案

第一/第二/第三阵列都是一样的,你粘贴(同一顺序)。

  $ datesCount =计数($ secondArray);
$ firstArrayLength =计数($ firstArray);
$ thirdArrayLength =计数($ thirdArray);为($ I = 0; $ I< $ thirdArrayLength; $ I ++)
{
    $ currentThirdArrayValue = $ thirdArray [$ i];    为($内= 0,$ firstArrayIndex = 0; $内与所述; $ datesCount; $内++ $ firstArrayIndex ++)
    {
        如果($ firstArrayIndex == $ firstArrayLength)
                $ firstArrayIndex = 0;        回声{$ secondArray [$内]} / {$ currentThirdArrayValue} / {$ firstArray [$ firstArrayIndex]}< BR /> \\ N的;
    }
}

会给你:

  2013年4月28日/ 13 /叶-19< BR />
2013年4月29日/ 13 /班次-1< BR />
2013年4月30日/ 13 /班次-1< BR />
2013年5月1日/ 13 /班次-1< BR />
2013年5月2日/ 13 /班次-1< BR />
2013年5月3日/ 13 /班次-1< BR />
2013年5月4日/ 13 /叶-19< BR />
2013年4月28日/ 10 /叶-19< BR />
2013年4月29日/ 10 /班次-1< BR />
2013年4月30日/ 10 /班次-1< BR />
2013年5月1日/ 10 /班次-1< BR />
2013年5月2日/ 10 /班次-1< BR />
2013年5月3日/ 10 /班次-1< BR />
2013年5月4日/ 10 /叶-19< BR />

等等......结尾:

  2013年5月1日/ 11 /班次-1< BR />
2013年5月2日/ 11 /班次-1< BR />
2013年5月3日/ 11 /班次-1< BR />
2013年5月4日/ 11 /叶-19< BR />

I want to merge 3 arrays.

My first one is:

Array ( [0] => Leaves-19 [1] => Shifts-1 [2] => Shifts-1 [3] => Shifts-1 [4] => Shifts-1 [5] => Shifts-1 [6] => Leaves-19 [7] => Leaves-19 [8] => Shifts-1 [9] => Shifts-1 [10] => Shifts-1 [11] => Shifts-1 [12] => Shifts-1 [13] => Leaves-19 [14] => Leaves-19 [15] => Shifts-1 [16] => Shifts-1 [17] => Shifts-1 [18] => Shifts-1 [19] => Shifts-1 [20] => Leaves-19 [21] => Leaves-19 [22] => Shifts-1 [23] => Shifts-1 [24] => Shifts-1 [25] => Shifts-1 [26] => Shifts-1 [27] => Leaves-19 [28] => Leaves-19 [29] => Shifts-1 [30] => Shifts-1 [31] => Shifts-1 [32] => Shifts-1 [33] => Shifts-1 [34] => Leaves-19 [35] => Leaves-19 [36] => Shifts-1 [37] => Shifts-1 [38] => Shifts-1 [39] => Shifts-1 [40] => Shifts-1 [41] => Leaves-19 )

My second is:

Array ( [0] => 2013-04-28 [1] => 2013-04-29 [2] => 2013-04-30 [3] => 2013-05-01 [4] => 2013-05-02 [5] => 2013-05-03 [6] => 2013-05-04 )

The third one is:

Array ( [0] => 13 [1] => 10 [2] => 12 [3] => 9 [4] => 14 [5] => 11 )

I want:

  • 2013-04-28 / 13 / Leaves-19
  • 2013-04-29 / 13 / Shifts-1
  • 2013-04-30 / 13 / Shifts-1
  • 2013-05-01 / 13 / Shifts-1
  • 2013-05-02 / 13 / Shifts-1
  • 2013-05-03 / 13 / Shifts-1
  • 2013-05-04 / 13 / Leaves-19
  • 2013-04-28 / 10 / Leaves-19
  • 2013-04-29 / 10 / Shifts-1
  • 2013-04-30 / 10 / Shifts-1
  • 2013-05-01 / 10 / Shifts-1
  • 2013-05-02 / 10 / Shifts-1
  • 2013-05-03 / 10 / Shifts-1
  • 2013-05-04 / 10 / Leaves-19
  • ...

Thansk for help.


What I tryed:

echo print_r($_POST['dayType'])."<hr />";
echo print_r($_POST['dayArr'])."<hr />";
echo print_r($_POST['userArr'])."<hr />";

//echo count($_POST['dayType'])." --- ".count($_POST['dayArr'])." --- ".count($_POST['userArr']);

// 2013-05-04 / 13 / Leaves-19
$loopNb1 = count($_POST['dayType']);
$loopNb2 = count($_POST['dayType'])/7;

for($a=0; $a<$loopNb1; $a++) {
    echo $_POST['dayType'][$a]."<br />";
}

echo "<hr />";

for($b=0; $b<$loopNb2; $b++) {
    echo $_POST['userArr'][1]."<br />";
}

解决方案

First/second/third arrays are the same that you pasted (Same order).

$datesCount        = count( $secondArray );
$firstArrayLength  = count( $firstArray );
$thirdArrayLength  = count( $thirdArray );

for( $i=0 ; $i < $thirdArrayLength ; $i++ )
{
    $currentThirdArrayValue = $thirdArray[$i];

    for( $inner=0, $firstArrayIndex=0 ; $inner < $datesCount ; $inner++, $firstArrayIndex++ )
    {
        if( $firstArrayIndex == $firstArrayLength )
                $firstArrayIndex = 0;

        echo "{$secondArray[$inner]} / {$currentThirdArrayValue} / {$firstArray[$firstArrayIndex]}<br/>\n";
    }
}

Will give you:

2013-04-28 / 13 / Leaves-19<br/>
2013-04-29 / 13 / Shifts-1<br/>
2013-04-30 / 13 / Shifts-1<br/>
2013-05-01 / 13 / Shifts-1<br/>
2013-05-02 / 13 / Shifts-1<br/>
2013-05-03 / 13 / Shifts-1<br/>
2013-05-04 / 13 / Leaves-19<br/>
2013-04-28 / 10 / Leaves-19<br/>
2013-04-29 / 10 / Shifts-1<br/>
2013-04-30 / 10 / Shifts-1<br/>
2013-05-01 / 10 / Shifts-1<br/>
2013-05-02 / 10 / Shifts-1<br/>
2013-05-03 / 10 / Shifts-1<br/>
2013-05-04 / 10 / Leaves-19<br/>

etc... ending with:

2013-05-01 / 11 / Shifts-1<br/>
2013-05-02 / 11 / Shifts-1<br/>
2013-05-03 / 11 / Shifts-1<br/>
2013-05-04 / 11 / Leaves-19<br/>

这篇关于合并多个阵列(),这取决于循环和数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆