Use associative arrays in PHP
#Programming study diary September 3, 2020
#What is an associative array? In an array, each value is numbered 0, 1, 2 … in order, and data can be specified by specifying that number, but in an associative array, it is managed by giving a name instead of a number can do. The box that uses both the array and the associative array is the same, but in the associative array, in order to make it easier to understand the handling after entering the data, you can retrieve the data for each name by specifying the name instead of the number.
#How to write First, review how to write an array.
<? php $ sports = array ("basketball", "baseball", "soccer"); echo $ sports ; ?>
Basketball and basketball, baseball and baseball, soccer and soccer are paired. In this case, it is not the 0th value and the 1st value as in the array, but the basketball value and the baseball value.
<? php $ sports = array ( "basketball" = "basketball", "baseball" = "baseball", "soccer" = "soccer" ); echo $ sports ["basketball"]; ?>