Cakephp使用Set :: extract来获取部分匹配值

时间:2012-12-03 15:51:27

标签: php cakephp

有没有办法使用正则表达式提取以提取下面数组中包含“.html”的值?

    Array
    (
        [urlset] => Array
            (
                [url] => Array
                    (
                        [0] => Array
                            (
                                [loc] => http://www.abc.com.au/computers
                                [lastmod] => 2012-12-02
                                [changefreq] => daily
                                [priority] => 0.5
                            )
                        [1] => Array
                            (
                                [loc] => http://www.abc.com.au/hp-scanjet-5590-digital-flatbed-scanner.html
                                [lastmod] => 2012-12-02
                                [changefreq] => daily
                                [priority] => 1.0
                            )

                        [2] => Array
                            (
                                [loc] => http://www.abc.com.au/stock-wardrobe-dark-walnut-doors.html
                                [lastmod] => 2012-12-02
                                [changefreq] => daily
                                [priority] => 1.0
                            )

                        [3] => Array
                            (
                                [loc] => http://www.abc.com.au/stock-wardrobe-white-mirror-door.html
                                [lastmod] => 2012-12-02
                                [changefreq] => daily
                                [priority] => 1.0
                            )
                     )
               )
  )

1 个答案:

答案 0 :(得分:0)

您可能没有理由使用正则表达式来搜索数组。 (而且它会比许多其他方式更难)。

如果您想在数组中搜索“.html”,只需构建一个简单的php foreach loop并使用PHP's array_search()检查您要查找的任何文字。