PHP Arrays
PHP Arrays
An array in PHP is a type that associates values to keys.
This type can be an array, list, hash table, dictionary, collection, stack, queue.
Simple array example
<html> <body> <?php $courses = array("PHP", "MySQL"); echo "I learn " . $courses[0] . " and " . $courses[1] . "."; echo "<br />"; echo count($courses), " courses."; ?> </body> </html>
Result
I learn PHP and MySQL.
2 courses.
PHP Associative Arrays example
<html> <body> <?php $price = array("PHP"=>"40", "MySQL"=>"32"); echo "The PHP price is ", $price['PHP']; echo "<br />"; echo "The MySQL price is ", $price['MySQL']; echo "<br />"; echo count($price), " courses."; ?> </body> </html>
Result
The PHP price is 40
The MySQL price is 32
2 courses.