How to extract parts of this array - PHP -


i trying print part of array, urls [href] "providerredirect.ashx" [0] [infinite]

array  (     [name] => hc redirect     [count] => 66     [frequency] => daily     [version] => 14     [newdata] => 1     [lastrunstatus] => partial     [thisversionstatus] => success     [nextrun] => sun jan 17 2016 14:03:08 gmt+0000 (utc)     [thisversionrun] => sat jan 16 2016 14:03:08 gmt+0000 (utc)     [results] => array      (         [collection1] => array             (                 [0] => array                     (                         [hotel search] => array                             (                                 [href] => https://www.domain.com/providerredirect.ashx?key=0.6359329.272723160.5179.gbp.1729297590&saving=410&source=32-0                                 [text] => view deal                             )                          [index] => 1                         [url] => https://www.domain.com/hotels/search?destination=place:london&checkin=2016-09-02&checkout=2016-09-09&rooms=1&adults_1=2&languagecode=en¤cycode=gbp&pagesize=50                     )                  [1] => array                     (                         [hotel search] => array                             (                                 [href] => https://www.domain.com/providerredirect.ashx?key=0.21199849.272723130.457.gbp.753573779&source=32-0                                 [text] => view deal                             )                          [index] => 2                         [url] => https://www.domain.com/hotels/search?destination=place:london&checkin=2016-09-02&checkout=2016-09-09&rooms=1&adults_1=2&languagecode=en¤cycode=gbp&pagesize=50                     )                  [2] => array                     (                         [hotel search] => array                             (                                 [href] => https://www.domain.com/providerredirect.ashx?key=0.23906211.272723157.1326.gbp.2008823249&source=32-0                                 [text] => view deal                             )                          [index] => 3                         [url] => https://www.domain.com/hotels/search?destination=place:london&checkin=2016-09-02&checkout=2016-09-09&rooms=1&adults_1=2&languagecode=en¤cycode=gbp&pagesize=50                     )                  [3] => array                     (                         [hotel search] => array                             (                                 [href] => https://www.domain.com/providerredirect.ashx?key=0.5242811.272723157.3854.gbp.1642352834&source=32-0                                 [text] => view deal                             )                          [index] => 4                         [url] => https://www.domain.com/hotels/search?destination=place:london&checkin=2016-09-02&checkout=2016-09-09&rooms=1&adults_1=2&languagecode=en¤cycode=gbp&pagesize=50                     )                  [4] => array                     (                         [hotel search] => array                             (                                 [href] => https://www.domain.com/providerredirect.ashx?key=0.675524.272723160.1457.gbp.2121712597&saving=18&source=32-0                                 [text] => view deal                             )                          [index] => 5                         [url] => https://www.domain.com/hotels/search?destination=place:london&checkin=2016-09-02&checkout=2016-09-09&rooms=1&adults_1=2&languagecode=en¤cycode=gbp&pagesize=50                     )                  [5] => array                     (                         [hotel search] => array                             (                                 [href] => https://www.domain.com/providerredirect.ashx?key=0.5743724.272723155.847.gbp.1001086600&source=32-0                                 [text] => view deal                             )                          [index] => 6                         [url] => https://www.domain.com/hotels/search?destination=place:london&checkin=2016-09-02&checkout=2016-09-09&rooms=1&adults_1=2&languagecode=en¤cycode=gbp&pagesize=50                     )                  [6] => array 

either use array_walk_recursive() function or write own function recursively traverse array , print urls.

suppose $arr array.

method(1):

array_walk_recursive($arr, function($item, $key) {     if ($key == "href") {         echo $item . "<br />";     } }); 

method(2):

function process_array($array){     foreach($array $key => $value){         if(is_array($value)){             process_array($value);         }else{             if($key == "href"){                 echo $value . "<br />";             }         }     } }  process_array($arr); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -