define()
` function. Here's an example :<?php
define('FRUITS', ['apple', 'banana', 'orange']);
echo FRUITS[1]; // outputs "banana"
?>
banana
define()
` function. The value of the constant is an array containing the strings `"apple"`, `"banana"`, and `"orange"`.echo
` statement outputs the value of the element at index 1 of the `FRUITS` array, which is `"banana"`.define()
` function in PHP 7.0 and later. In earlier versions of PHP, you would need to use the `const
` keyword to define a scalar constant, and the `define()
` function with an array variable to define an array constant. <?php
const FRUITS = ['apple', 'banana', 'orange'];
define('VEGGIES', ['carrot', 'celery', 'broccoli']);
echo FRUITS[0];
echo VEGGIES[2];
?>
apple
broccoli
const
` keyword. An array constant named `VEGGIES` is defined using the `define()
` function with an array variable. echo
` statements output the values of the elements at index 0 of the `FRUITS` array and index 2 of the `VEGGIES` array.