happy cat image

everdevel

coding

login
NotificationX
  • Currently, only notices of comments are displayed.
  • no comment or please login

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

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

The way you print an array is not too different.

Constant Array Output Method

 echo constant name[index];

So let's look at an example.

<?php
    define('DISNEY',['MICKEY', 'MINNIE', 'DUFFY']);
    echo DISNEY[0];
    echo '<br>';
    echo DISNEY[1];
    echo '<br>';
    echo DISNEY[2];
?>

Here is the resulting image

php define array

Thank you for visiting. If you have any inquiry or explanation of mistakes, please use the comments below.


    
    

Back to the course

ALL COMMENTS 0

Sort by