Examples of parsing array values on screen. Some examples for beginners.
Array content:
If you have an array, but you don't know what does it contain then you can use print_r() function. The function displays information about a variable in a way that's readable by humans.Echo array:
If you have the most basic array you can use foreach to echo it. You can also echo key names.Source code viewer
// First example: foreach ($a as $var) echo $var; // Result: abcd // Second example: echo 'key: '.$key.' value: '.$var.'<br />'; // Result in parsed html will be: // key: key1 value: a // key: key2 value: b // key: key3 value: c // key: key4 value: dProgramming Language: PHP
Echo array as list:
You can also create lists out of arrays. Example code:Result:Source code viewer
echo '<ul>'; foreach ($a as $var) echo '<li>'.$var.'</li>'; echo '</ul>';Programming Language: PHP
- a
- b
- c
- d