Var_dump() is a powerful native PHP function that will output detailed information about any type of data contained in a PHP program, including arrays. Print More Detailed Array Data with var_dump() The easiest way to show data from an array in PHP is to loop through it using a foreach statement and echo each item individually. Print Data in PHP Array with foreach loop. Here is a demonstration of how to use print_r(): In this tutorial, we will learn some different ways of printing/echoing an array in PHP. The native PHP print_r() function will show the entire array including index numbers and values without needing to loop through it. $items = foreach ( $items as $key => $value ) Key is: 0 value is: apple The most common method to print the contents of an array is using the printr() function, which displays the human information about a variable. These lines of code will return us the first element from the array. The easiest way to show data from an array in PHP is to loop through it using a foreach statement and echo each item individually. myarr array(100, 200, 300, 400, 00) echo reset(myarr). Print Data in PHP Array with foreach loop Here is the code.In this tutorial, we will learn some different ways of printing/echoing an array in PHP. We can use print_r funciton which returns variables in human readable format. Using sizeof function to display all elements using for loop $a= array("Three", "two", "Four", "five","ten") įor($i=0 $i85,"Raju"=>75,"Alex"=>48,"Ronald"=>52) If you are in an urge, the quick example below will save your time. It outputs the same as what the echo statement does. PHP language has the print () function also. PHP echo is a one of the widely used statements. Here is the code to create and display the value of PHP echo to print HTML, New Line, Text and Array by Vincy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |