Example Constant Arrays In PHP 7

- 1 min

Array constants can now be defined using the define() function. In PHP 5.6, they could only be defined using const keyword.

Example

<?php
   //define a array using define function
   define('animals', [
      'dog',
      'cat',
      'bird'
   ]);
   print(animals[1]);
?>

It produces the following browser output:

cat
Nurul Fajar

Nurul Fajar

Mahasiswa banyak acara

comments powered by Disqus
rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora