douji6735 2018-06-22 07:41
浏览 25

从其他阵列获取组合

I have two array

First

array(
0 => 100000,
1 => 50000,
2 => 100000,
3 => 100000);

Second

array(
0 => 150000,
1 => 200000,);

The problem is I want to get the combination from first array that formed each second array.

Example Second array index 0 can be formed from first array index 0 and 1 and second array index 1 can be formed from first array index 2 and 3

I want to achieve like this

[0 => [0,1] , 1 => [2,3]]

Thanks for the help.

  • 写回答

3条回答 默认 最新

  • douzhen1234 2018-06-22 07:53
    关注

    Try with following code:

    $arr = array(
    0 => 100000,
    1 => 50000,
    2 => 100000,
    3 => 100000);
    $count = $val = 0;
    $newArr = [];
    foreach($arr as $a){
       $val += $a;
       $count++;
       if($count == 2){
         $newArr[] = $val;
         $val = $count = 0; 
       }
    }
    print_r($newArr); die;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析