PHP print array
This is a small tutorial how to print array in PHP. You will learn all the way you can display, print the content of an array.
Step 1 - Introduction
PHP print array
Arrays are very usefull data types in PHP. Besides this they are very flexible as well. In PHP there are more ways how to print array content. Regarding what information you want to display we can make some categories.
- You want to print only one array element value
- You want to print all of the PHP array values
- You want to print the complete array with keys, values maybe data types
Code:
// Create a new array $colorList2[] = "red"; $colorList2[] = "green"; $colorList2[] = "blue"; $colorList2[] = "black"; $colorList2[] = "white";
Don't forget to use the correct key index as if you use the array name without key then it will print only the text "Array" as the actual variable type is array. However if you define a wrong key you will print nothing.
The following examples demonstartes some wrong usage:
However the code in the 2. and 3. line should be ok, if the array have such elements. So if you extend your array as follows then the last 2 statement will print valid values.
Code:
$colorList2[220] = "yellow"; $colorList2["apple"] = "apple-green";
Next Step of PHP print array
Tags: php print array, print array, php array, php, print, array
| PHP print array - Table of contents |
|---|
| Step 1 - Introduction |
| Step 2 - Print complete php arrays |