I have an multidimensional array which includes IDs and URLs. I would like to output the URLs only.
$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 is it possible to take control of what I want to show?
To solve this, we will use the array_column() and function of array_column. The simple code to search the value in multidimensional array is described as follows: array_search($value['id'], array_column($studentsAddress, 'user_id'))
Code Inspection: Duplicate array keysIf multiple elements in the array declaration use the same key, only the last one will be used, and all others will be overwritten.
PHP array_key_exists() Function The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
Use array_column
that will prevent you from foreach loop
$url = array_column($abstract_details, 'url');
echo implode('<br/>', $url);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With