conversion functions between arrays and variables
- List () language structure
-
- Format: void list (mixed varname1[,mixed varname2[,mixed ...]) = array arr, assigning a set of variables in one step.
- Note: the list () language structure is used only for arrays of numeric "keys" and requires the number "key" to increment continuously from 0;
- Extract () function
-
- Format: int extract (array arr), use an array of arr to define a set of variables, where the variable name is the key name of the ARR element, and the variable value is the value of the array arr element "key".
- Compact () function
-
- Format: Array compact (mixed varname1[,mixed varname2[,mixed ...]), returns an array of "keys" for each element named variable name varname1 (varname2 ...), each of the array elements " Value "is Variable varname1 (varname2 ...) The value.
Array Traversal language structure
- foreach (array as $value)
- foreach (array as $key = = $value)
For example:
<?PHP$interests[2] = "Music";$interests[6] = "movie";$interests[1] = "Computer";$interests[] = "Software";foreach($interests as $value) { Echo $value." <br> ";}foreach($interests as $key=$value) { Echo $key. "=".$value. "<br>" ;}?>
Results:
PHP array functions (2)