
PHP ONLINE ARRAY FORMATTER CODE
The above code output will look like this in your browser: Code Output: We can access each element of an array using its index number. Remember, the index number of an array starts from 0. And also, I added a tag to display each value of an array on a new line. I used an echo statement with an array name and index number on each line.
PHP ONLINE ARRAY FORMATTER HOW TO
Now, let’s see the PHP code to print an array using echo statements.Įxample 3.1: This example will show you how to use an echo statement to print all the values of an array one by one. While in terms of arrays, echo is not the only solution but it is still helpful in many cases.įor example, echo helps a lot when we want to print a single value of an array. In PHP, whenever we want to print something, we use echo statements. The echo statement is useful in some cases, now let’s see that in the next method. But there is an echo statement that we use mostly to print a single array element. We use these variables inside the loop to print the keys and values of an associative array. You can give any name to $key and $value variables, these variables will hold the value of named indexes and their values.In that Foreach loop, I used the array name ($students) with $key and $value variables. And the indentation you’re seeing is optional, you can write the associative array on just 1 line.

The length of the above-indexed array is 4 which starts from 0. 5, in the above code, I used the count() function to get the length of an array in numbers and stored it in a variable ( $arrlength).

Now, let’s print all the values of an array using for loop. In this example, I will create an indexed array with the name $students. Also, you can print each array element on a new line or inside the HTML table. By using a loop, you can print all the values of an array at the same time in different ways.įor example, you can use this PHP method to print an array line by line. Using for loop is the most suitable way to print PHP array content. Tip: Don’t know how to run PHP on your PC? See this guide on how to run PHP code.

Not just simple indexed arrays, examples to print associative arrays, and multi-dimensional arrays are also included in this guide. In PHP, We use the Following 6 Methods to Print Arrays :Īlso, you will learn each method with an example. And we’re going to discuss all that in this tutorial. And in PHP, we have various methods to print arrays. Whether it’s an indexed array, associative array, or multidimensional array, you’ll see each of them in this all-in-one guide.Īrrays are very useful when we want to store multiple values in one variable. You will know how to print array values in different ways using these methods. You’ll see all 6 easy methods with examples. In this PHP tutorial, you’ll learn how to print an array.
