Display Array Values in PHP

Display Array Values in PHP. In this program, we can print the constant array using a defined function. 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.

<?php
define("fruit", [
"apple",
"orange",
"banana"
]);
echo fruit[2];
?>

 

Output:

banana

Consonant in PHP

Except for magic constants, which aren’t actually constants, PHP constants are names or identifiers that can’t be modified throughout the execution of the script. Constants in PHP can be defined in two ways: The define() function is used.

Define Function in PHP

A constant is defined with the define() function. Constants are similar to variables, with the following exceptions: The value of a constant cannot be modified once it has been set. A leading dollar symbol ($) is not required for constant names. Regardless of scope, constants can be accessed.

Array in PHP

Arrays are a form of data structure in PHP that allows us to store several pieces of a comparable data type in a single variable, saving us the trouble of establishing a distinct variable for each data. The array() function in PHP generates and returns an array. It supports the creation of indexed, associative, and multidimensional arrays.