从数组中提取Specific参数值

时间:2014-09-30 09:31:33

标签: php

我有一个像这样的数组

 [0] => Array
          (
             [0] => LBLdss_COLLEsdfCTIONS_RsdfsdEPORT_TITfsdfLE
            [1] => 
            [2] => 
            [3] => Array
                (
                    [Administration] => Array
                        (

                        [bidsflldsf6] => Array
                            (
                                [0] => themes/Care2012/images/Payments
                                [1] => LsdfBL_OPsddfD_BIsfdfsLLING_SsdfdsUMsdfMARY_TITLE
                                [2] => LsdfsdBL_OPDfdsfd_BILfdsLING_dsfdsSUMMARY
                                [3] => ./index.php?module=Rsdfepfdsforts&action=reposfdfdsrtsel&rname=Opdpasfdfypdf
                            )

                        [bilhghjgl_pat_reg] => Array
                            (
                                [0] => themsdfsdes/Casfdfre2aasd012/imasdfges/Pasdymesddfnts
                                [1] => LBL_sdfsPAT_RsdfEG_TsdfITLE
                                [2] => LBL_PdfsdAT_sfdREG_TdsfdITLE_DsdfsETAIL
                                [3] => ./index.php?module=Rexcvpofdsrts&action=reportsel&rname=Pacxvtregcollxcvectionpdf
                            )

                    )

            )

        [4] => 
    )

现在我需要从这个索引中提取rname的值[3] => ./index.php?module=Rexcvpofdsrts&action=reportsel&rname=Pacxvtregcollxcvectionpdf(在这种情况下是Pacxvtregcollxcvectionpdf)并且必须保存它 我可以尝试爆炸功能但是对我来说很重要,因为我的数组大小很大 请帮忙解决这个问题 感谢

3 个答案:

答案 0 :(得分:0)

尝试放置一个foreach来循环数组并制定一个正则表达式来提取你的参数。像这样:

foreach($youvar as $text) {
    preg_match('$rname=(.+?)$', $text, $rname[]) 
}

之后你可以在$ rname上尝试print_r并适应你。

答案 1 :(得分:0)

请尝试以下方法: -

$a = explode("rname=", index[3]);

echo $a[1;]

答案 2 :(得分:0)

代码

$array = array(
    './index.php?module=Rsdfepfdsforts&action=reposfdfdsrtsel&rname=Opdpasfdfypdf',
    './index.php?module=Rexcvpofdsrts&action=reportsel&rname=Pacxvtregcollxcvectionpdf',
);

function getRname($str){
    //return null if not found
    preg_match('/rname\=([a-zA-Z]+)($|&)/', $str , $matches);
    return $matches[1];
}

foreach($array as $str){
    echo "Rname: " . getRname($str). "<br/>";
}

结果

Rname: Opdpasfdfypdf
Rname: Pacxvtregcollxcvectionpdf

试试吗?