PHP echo Array Key Name and Value

PHP echo Array Key Name and Value. A Php program to print the array element in a programming language. In this program, we can print the array elements in PHP. An array is a data structure that includes a collection of elements. The data types of these things are frequently the same, such as an integer or a string. For example, a search engine might utilise an array to store Web sites discovered during a user’s search.

$fruit=array("apple","orange","strawberry","pineapple"); 
echo "Fruits are $fruit[0], $fruit[1], $fruit[2] and $fruit[3]";
?>

 

Output:

Fruits are apple, orange, strawberry and pineapple

Array in PHP

Arrays are a form of data structure in PHP that allows us to store several pieces of the same data type in a single variable, saving us the time and effort of having to create a new variable for each data type. The arrays are useful for creating a list of similar-type elements that can be accessed by their index or key.

Operator in PHP

In PHP, the $ operator is used to declare variables. A variable in PHP begins with the $ sign and is followed by the variable’s name. An operator in PHP is a symbol that performs actions on operands. Operators, to put it simply, are used to perform operations on variables or values.