QUIZGUM

Coding Class

Quizgum : define array

Declaring Arrays as Constants

You learned how to declare an array earlier.
Arrays can also be declared as constants.
Assigning a different value does not change the value.

How to declare an array in a constant

  1. define( 'constant name' , ['array value1' , 'array value2' , 'array value3']);

The way you print an array is not too different.

Constant Array Output Method

  1. echo constant name[index];

So let's look at an example.

  1. <?php
  2. define('DISNEY',['MICKEY', 'MINNIE', 'DUFFY']);
  3. echo DISNEY[0];
  4. echo '<br>';
  5. echo DISNEY[1];
  6. echo '<br>';
  7. echo DISNEY[2];
  8. ?>

Here is the resulting image

php define array