In this example you will learn, how to Get the First Element of an Array in PHP. If you know the exact index or key of an array you can easily get the first element, like this:
1 2 3 4 5 6 7 8 9 |
<?php // A sample indexed array $cities = array("London", "Paris", "New York"); echo $cities[0]; // Outputs: London // A sample associative array $fruits = array("a" => "Apple", "b" => "Ball", "c" => "Cat"); echo $fruits["a"]; // Outputs: Apple ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.