Array
(
    [0] => Array
        (
            [title22] => 噩噩噩噩噩噩噩噩噩噩噩噼噼啪啪
        )    [1] => Array
        (
            [id] => 479
            [questionId] => 0
            [projectId] => 11
            [title] => 11
            [optionA] => 对
            [optionB] => 11
            [optionC] => 11
            [optionD] => 11
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 11
            [rightAnswer] => A
            [info] => 11111
            [aid] => 49
        )    [2] => Array
        (
            [title22] => 钱钱钱钱钱钱钱钱钱钱
        )    [3] => Array
        (
            [id] => 478
            [questionId] => 0
            [projectId] => 11
            [title] => 1
            [optionA] => 对
            [optionB] => 对
            [optionC] => 1
            [optionD] => 1
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 11
            [rightAnswer] => AB
            [info] => 1111111
            [aid] => 49
        )    [4] => Array
        (
            [id] => 480
            [questionId] => 0
            [projectId] => 11
            [title] => 2222
            [optionA] => 222
            [optionB] => 22
            [optionC] => 22
            [optionD] => 22
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 22
            [rightAnswer] => A
            [info] => 22222222222
            [aid] => 50
        )    [5] => Array
        (
            [title22] => 就斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较经济
        )    [6] => Array
        (
            [id] => 481
            [questionId] => 0
            [projectId] => 11
            [title] => 额的的
            [optionA] => 1
            [optionB] => 2
            [optionC] => 3
            [optionD] => 4
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 10
            [rightAnswer] => A
            [info] => 反反复复反反复复反反复复吩咐分
            [aid] => 58
        )    [7] => Array
        (
            [id] => 482
            [questionId] => 0
            [projectId] => 11
            [title] => 法国队四方股份
            [optionA] => 1
            [optionB] => 2
            [optionC] => 3
            [optionD] => 4
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 10
            [rightAnswer] => A
            [info] => 感到十分vsa
            [aid] => 58
        )    [8] => Array
        (
            [title22] => 啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
        )    [9] => Array
        (
            [id] => 483
            [questionId] => 0
            [projectId] => 11
            [title] => 法规和斯维尔
            [optionA] => 1
            [optionB] => 2
            [optionC] => 3
            [optionD] => 4
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 10
            [rightAnswer] => A
            [info] => 对符合国家亏了范德萨
            [aid] => 59
        )    [10] => Array
        (
            [id] => 484
            [questionId] => 0
            [projectId] => 11
            [title] => 俄方岁的法国火炬计划购房
            [optionA] => 分公司地方
            [optionB] => 公司的分公司
            [optionC] => 发送给法国
            [optionD] => 根深蒂固
            [part] => 4
            [must] => 0
            [type] => 1
            [forbid] => 0
            [] => 10
            [rightAnswer] => A
            [info] => 广东分公司
            [aid] => 59
        ))
怎么才能把 只有 一个值的数组合并到下一个数组

解决方案 »

  1.   

    例如把
    array(
    [0] => Array
      (
      [title22] => 噩噩噩噩噩噩噩噩噩噩噩噼噼啪啪
      )  [1] => Array
      (
      [id] => 479
      [questionId] => 0
      [projectId] => 11
      [title] => 11
      [optionA] => 对
      [optionB] => 11
      [optionC] => 11
      [optionD] => 11
      [part] => 4
      [must] => 0
      [type] => 1
      [forbid] => 0
      [] => 11
      [rightAnswer] => A
      [info] => 11111
      [aid] => 49
      ))改成
    array(
      [1] => Array
      (
      [title22] => 噩噩噩噩噩噩噩噩噩噩噩噼噼啪啪
      [id] => 479
      [questionId] => 0
      [projectId] => 11
      [title] => 11
      [optionA] => 对
      [optionB] => 11
      [optionC] => 11
      [optionD] => 11
      [part] => 4
      [must] => 0
      [type] => 1
      [forbid] => 0
      [] => 11
      [rightAnswer] => A
      [info] => 11111
      [aid] => 49
      ))这样的  
      

  2.   

    将就吧...简单的for.$TestArray=array(array('0'=>'a'),array('1'=>'1122','2'=>'333'),array('2'=>'b'),array('3'=>'3344','44'=>'2222'),
    array('4'=>'c'),array('5'=>'5566','4'=>'334343'),array('444'=>'test','aaa'=>'cccc'),array('eee'=>'3242','94js'=>'222'));/**
     *
     * 合并函数
     * @param 需要合并的数组 $Array
     * @return 返回数组array: $Array
     */
    function Marray($Array){
    $NewArray=array();
    for ($i=0;$i<count($Array);$i++){
    if (count($Array[$i])==1){
    $NewArray[]=array_merge($Array[$i],$Array[$i+1]);
    }else{
    if (count($Array[$i-1])!==1){
    $NewArray[]=$Array[$i];
    }
    }
    }
    return $NewArray;
    }
    //测试结果
    $Test=Marray($TestArray);
    print_r($Test);/**
     Array
     (
     [0] => Array
     (
     [0] => a
     [1] => 1122
     [2] => 333
     ) [1] => Array
     (
     [0] => b
     [1] => 3344
     [2] => 2222
     ) [2] => Array
     (
     [0] => c
     [1] => 5566
     [2] => 334343
     ) [3] => Array
     (
     [444] => test
     [aaa] => cccc
     ) [4] => Array
     (
     [eee] => 3242
     [94js] => 222
     ) ) */
      

  3.   

    谢谢 我 写了一个 更简单的方法 for($i=0;$i<count($a)+1;$i++) {
        if($a[$i][id]=="") {
            $a[$i+1] += $a[$i];
    unset($a[$i]);
        }
    }print_r($a);/*测试结果Array
    (
        [1] => Array
            (
                [id] => 479
                [questionId] => 0
                [projectId] => 11
                [title] => 11
                [optionA] => 对
                [optionB] => 11
                [optionC] => 11
                [optionD] => 11
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 11
                [rightAnswer] => A
                [info] => 11111
                [aid] => 49
                [title22] => 噩噩噩噩噩噩噩噩噩噩噩噼噼啪
            )    [3] => Array
            (
                [id] => 478
                [questionId] => 0
                [projectId] => 11
                [title] => 1
                [optionA] => 对
                [optionB] => 对
                [optionC] => 1
                [optionD] => 1
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 11
                [rightAnswer] => AB
                [info] => 1111111
                [aid] => 49
                [title22] => 钱钱钱钱钱钱钱钱钱钱
            )    [4] => Array
            (
                [id] => 480
                [questionId] => 0
                [projectId] => 11
                [title] => 2222
                [optionA] => 222
                [optionB] => 22
                [optionC] => 22
                [optionD] => 22
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 22
                [rightAnswer] => A
                [info] => 22222222222
                [aid] => 50
            )    [6] => Array
            (
                [id] => 481
                [questionId] => 0
                [projectId] => 11
                [title] => 额的的
                [optionA] => 1
                [optionB] => 2
                [optionC] => 3
                [optionD] => 4
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 10
                [rightAnswer] => A
                [info] => 反反复复反反复复反反复复吩咐分
                [aid] => 58
                [title22] => 就斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较经济
            )    [7] => Array
            (
                [id] => 482
                [questionId] => 0
                [projectId] => 11
                [title] => 法国队四方股份
                [optionA] => 1
                [optionB] => 2
                [optionC] => 3
                [optionD] => 4
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 10
                [rightAnswer] => A
                [info] => 感到十分vsa
                [aid] => 58
            )    [9] => Array
            (
                [id] => 483
                [questionId] => 0
                [projectId] => 11
                [title] => 法规和斯维尔
                [optionA] => 1
                [optionB] => 2
                [optionC] => 3
                [optionD] => 4
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 10
                [rightAnswer] => A
                [info] => 对符合国家亏了范德萨
                [aid] => 59
                [title22] => 啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
            )    [10] => Array
            (
                [id] => 484
                [questionId] => 0
                [projectId] => 11
                [title] => 俄方岁的法国火炬计划购房
                [optionA] => 分公司地方
                [optionB] => 公司的分公司
                [optionC] => 发送给法国
                [optionD] => 根深蒂固
                [part] => 4
                [must] => 0
                [type] => 1
                [forbid] => 0
                [] => 10
                [rightAnswer] => A
                [info] => 广东分公司
                [aid] => 59
            ))*/
      

  4.   

    其实你的代码应该判断 isset 比你判断是不是空效率更高.