Skip to content

Echo Array values in PHP ?

This is very simple and common task, But many PHP newbies(beginners) don’t know about it. To see the Structure of PHP array , you have to use PHP built in function called print_r(),This will give a listing of all the items in the array(including multidimensional arrays). The following example demonstrate how to create and display arrays in PHP.

Example :


 Apple [1] => Apricot [2] => Avocado [3] => Banana [4] => Bilberry [5] => Blackberry [6] => Blackcurrant [7] => Blueberry [8] => Currant [9] => Cherry )
?>

Function in the Above PHP Example

array(): array() function is used for creating arrays in php , The syntax is something like this “index => values” Separated by commas, index type may be string or integer , if you leave index while writing array values, index will start form zero,If index is an integer, next generated index will be the biggest integer index + 1.and one more important point is two identical indexes are not allowed, if two index are same second value will be consider means last overwrite the first

Note : array() is a language construct used to represent literal arrays, and not a regular function.

print_r — Prints human-readable information about a variable

0 0 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments