Multidimensional array: how to get all the values ​​of a specific key?

I have a multidimensional array that includes identifiers and URLs. I would like to output only urls.

$abstract_details = array(
                        array(
                            'id' => 68769782222,
                            'url' => 'http://yourclick.ch'
                        ),
                        array(
                            'id' => 111,
                            'url' => 'http://google.com'
                        )
                    );

foreach ($abstract_details as $abstract_detail) {
    foreach ($abstract_detail as $get_abstract_detail) {
        $result .= $get_abstract_detail . '<br>';
    }
}

When I run my code, I get both information. How can I take control of what I want to show?

+4
source share
3 answers

Here you don’t even need a nested loop if you want to print only the URL. Try the following:

foreach ($abstract_details as $abstract_detail) {
   $result .= $abstract_detail['url'] . '<br>';
}

Conclusion:

http://yourclick.ch
http://google.com
+3
source

Use that will prevent you from foreach loop array_column

$url = array_column($abstract_details, 'url');

echo implode('<br/>', $url); 
+10
source
foreach ($abstract_details as $abstract_detail) {
       $result .= $abstract_detail['url']
    }
+2

All Articles