dsgwdigu84950 2013-12-10 15:24
浏览 37

从数组中获取一次值

I've got an array generated from a SQL query :

<pre>
$df = $bdd->query('select * from V_Customer_Link where ref_customer in (select       ref_customer from V_Customer_Link group by ref_customer having count(*) >=4)');
$result = $df->FetchAll();
$df->closeCursor();
</pre>

When i do a print_r($result) i've got this :

<pre>
Array
(
    [0] => Array
        (
            [docno] => 59
            [0] => 59
            [ref_customer] => ALFKI
        [1] => ALFKI
        [type_de_document] => 2
        [2] => 2
        [TypeDeDoc] => Rib
        [3] => Rib
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=59.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=59.1&child=true
    )

[1] => Array
    (
        [docno] => 60
        [0] => 60
        [ref_customer] => ALFKI
        [1] => ALFKI
        [type_de_document] => 1
        [2] => 1
        [TypeDeDoc] => Carte Identité
        [3] => Carte Identité
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=60.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=60.1&child=true
    )

[2] => Array
    (
        [docno] => 61
        [0] => 61
        [ref_customer] => ALFKI
        [1] => ALFKI
        [type_de_document] => 3
        [2] => 3
        [TypeDeDoc] => Kbis
        [3] => Kbis
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=61.2&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=61.2&child=true
    )

[3] => Array
    (
        [docno] => 62
        [0] => 62
        [ref_customer] => ALFKI
        [1] => ALFKI
        [type_de_document] => 4
        [2] => 4
        [TypeDeDoc] => Contrat
        [3] => Contrat
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=62.2&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=62.2&child=true
    )

[4] => Array
    (
        [docno] => 66
        [0] => 66
        [ref_customer] => BOLID
        [1] => BOLID
        [type_de_document] => 4
        [2] => 4
        [TypeDeDoc] => Contrat
        [3] => Contrat
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=66.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=66.1&child=true
    )

[5] => Array
    (
        [docno] => 67
        [0] => 67
        [ref_customer] => BOLID
        [1] => BOLID
        [type_de_document] => 1
        [2] => 1
        [TypeDeDoc] => Carte Identité
        [3] => Carte Identité
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=67.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=67.1&child=true
    )

[6] => Array
    (
        [docno] => 68
        [0] => 68
        [ref_customer] => BOLID
        [1] => BOLID
        [type_de_document] => 3
        [2] => 3
        [TypeDeDoc] => Kbis
        [3] => Kbis
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=68.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=68.1&child=true
    )

[7] => Array
    (
        [docno] => 69
        [0] => 69
        [ref_customer] => BOLID
        [1] => BOLID
        [type_de_document] => 5
        [2] => 5
        [TypeDeDoc] => Liasse Fiscale
        [3] => Liasse Fiscale
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=69.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=69.1&child=true
    )

[8] => Array
    (
        [docno] => 70
        [0] => 70
        [ref_customer] => BOLID
        [1] => BOLID
        [type_de_document] => 2
        [2] => 2
        [TypeDeDoc] => Rib
        [3] => Rib
        [link] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=70.1&child=true
        [4] => http://localhost/TWA/Client/WEB/Viewer/Viewer.aspx?DocNo=70.1&child=true
    )

)

As you can see, there is only 2 differents ref_customer. In the futur, there will be more.

I would like to dispay information from this array like this :

ALFKI : Rib, Carte Identité, Kbis, Contrat

BOLID : Rib, Carte Identité, Kbis, Contrat, Liasse fiscale

If i do a for or a while , the value ref_customer will be repeated each time.

How can i limit this value once and get all the other.

I hope my description is clear enough.

Thanks.

  • 写回答

3条回答 默认 最新

  • doww38701 2013-12-10 15:35
    关注

    I'd create another array based on ref_customer and implode the values.

    untested, but something along these lines

    $ref_customers = array();
    foreach($result as $r) {
        $ref_customers[$r['ref_customer']][] = $r['TypeDeDoc'];
    }
    
    foreach($ref_customers as $ref => $typededoc) {
        echo $ref . ' : ' . implode(", ", $typededoc);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线