2017-01-31 55 views
0

这是我得到的数组,请帮助我获得输出,如同相同的键值一样,为每个相同的类别创建不同的数组。我加入所需的输出低于PHP通过键值对数组进行不同的设置

Array 
(
[2] => Array 
    (
     [ans_type] => single 
     [ques] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
     [opt1] => Analog video konektörü 
     [opt2] => Sadece ses konektörü 
     [opt3] => (MNC) 
     [opt4] => Analog ses konektörü 
     [opt5] => Sadece video konektörü 
     [ans] => C 
     [cat] => Genel 
     [title] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
     [quiz_name] => history 
    ) 

[3] => Array 
    (
     [ans_type] => single 
     [ques] => Aşağıdaki konektör tiplerinden hangileri coaxial kablo ile kullanılır 
     [opt1] => ST 
     [opt2] => MT RJ 
     [opt3] => (BNC) 
     [opt4] => LC 
     [opt5] => F-connector 
     [ans] => E 
     [points] => 2 
     [cat] => Genel 
     [title] => Aşağıdaki konektör tiplerinden hangileri coaxial kablo ile kullanılır 
     [quiz_name] => geography 
    ) 

    ) 

这里是所需的输出

  Array 
    (
     [0] => Array 
      (
       [0] => Array 
       (
       [ans_type] => single 
       [ques] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
       [opt1] => Analog video konektörü 
       [opt2] => Sadece ses konektörü 
       [opt3] => (MNC) 
       [opt4] => Analog ses konektörü 
       [opt5] => Sadece video konektörü 
       [ans] => C 
       [cat] => Genel 
       [title] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
       [quiz_name] => history 
       ) 

       [1] => Array 
        (
         [ans_type] => single 
         [ques] => Aşağıdaki konektör tiplerinden hangileri coaxial kablo ile kullanılır 
         [opt1] => ST 
         [opt2] => MT RJ 
         [opt3] => (BNC) 
         [opt4] => LC 
         [opt5] => F-connector 
         [ans] => E 
         [points] => 2 
         [cat] => Genel 
         [title] => Aşağıdaki konektör tiplerinden hangileri coaxial kablo ile kullanılır 
         [quiz_name] => history 
        ) 
      ) 
      [1] => Array 
      (
       [0] => Array 
      (
       [ans_type] => single 
       [ques] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
       [opt1] => Analog video konektörü 
       [opt2] => Sadece ses konektörü 
       [opt3] => (MNC) 
       [opt4] => Analog ses konektörü 
       [opt5] => Sadece video konektörü 
       [ans] => C 
       [cat] => Genel 
       [title] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
       [quiz_name] => geography 
      ) 
      )  



    ) 
+1

修改你的问题,并制定有关的您正在寻找的数组合并的“规则”。 –

+0

感谢您的回复,fi你可以给我一个简单的例子,这将有助于 – smrutiranjanpanda

+0

我需要[quiz_name] =>历史这个关键值对,我们发现类似于这个关键值,那么它会得到一个不同的阵列 – smrutiranjanpanda

回答

0

如果你能有结果数组作为类别名称的东西很简单的指标。
$first是你的第一阵列

$first = Array 
(
[2] => Array 
(
    [ans_type] => single 
    [ques] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
    [opt1] => Analog video konektörü 
    ..... 
    ..... 

然后做一个forach环路$first阵列

$result = array(); 
foreach($first as $row){ 
    $index = $row['quiz_name']; 
    $result[$index][] = $row; 
} 

var_dump($result); 

输出会像上,

Array 
    (
    ['history'] => Array 
     (
      [0] => Array 
        (
        [ans_type] => single 
        [ques] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
        [opt1] => Analog video konektörü 
        [opt2] => Sadece ses konektörü 
        [opt3] => (MNC) 
        [opt4] => Analog ses konektörü 
        [opt5] => Sadece video konektörü 
        [ans] => C 
        [cat] => Genel 
        [title] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
        [quiz_name] => history 
       ) 

      [1] => Array 
       (
        [ans_type] => single 
        [ques] => Aşağıdaki konektör tiplerinden hangileri coaxial kablo ile kullanılır 
        [opt1] => ST 
        [opt2] => MT RJ 
        [opt3] => (BNC) 
        [opt4] => LC 
        [opt5] => F-connector 
        [ans] => E 
        [points] => 2 
        [cat] => Genel 
        [title] => Aşağıdaki konektör tiplerinden hangileri coaxial kablo ile kullanılır 
        [quiz_name] => history 
       ) 
     ) 
    ['geography'] => Array 
     (
      [0] => Array 
      (
        [ans_type] => single 
        [ques] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
        [opt1] => Analog video konektörü 
        [opt2] => Sadece ses konektörü 
        [opt3] => (MNC) 
        [opt4] => Analog ses konektörü 
        [opt5] => Sadece video konektörü 
        [ans] => C 
        [cat] => Genel 
        [title] => Aşağıdakilerden hangisi Displayport'un özelliklerindendir 
        [quiz_name] => geography 
      ) 
     )  
) 
+0

谢谢你,先生 !!!真的很感谢:) – smrutiranjanpanda

+0

不客气..希望你明白了... –

相关问题