This is an array i have
<?php $page['Home']='index.html'; $page['Service']='services.html'; ?>
How do i get to echo something like this for individual one like
Home is at index.html
and again how can i do this through a loop and echo all?
Either use array_column() for PHP 5.5: $foo = array(["type"=>"a"], ["type"=>"b"], ["type"=>"c"]); $result = array_column($foo, 'type'); Or use array_map() for previous versions: $result = array_map(function($x) { return $x['type']; }, $foo);
The array_keys() function is used to get all the keys or a subset of the keys of an array. Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned.
<? php $colors = array("Red", "Green", "Blue", "Yellow", "Orange"); // Loop through colors array foreach($colors as $value){ echo $value . "<br>"; } ?>
foreach($page as $key => $value) { echo "$key is at $value"; }
For 'without loop' version I'll just ask "why?"
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