Home Tutorial Php List PHP list constants

 
 

PHP list constants
Posted on: November 2, 2009 at 12:00 AM
In this PHP tutorial, we will learn how to list the constants used in our PHP program. And we will show example which prints the all constants defined.

  • PHP constants defined can be listed using the function get_defined_constants().
  • get_defined_constants() returns the system defined and user defined constants in associative array form.


Example of PHP list Constants
<?php
    define("g",9.8);
    define("PI",31.4);
    $cons
=get_defined_constants();
    echo
"<pre>";
    foreach
($cons as $key=>$val)
      {
      echo
"<br>$key=>$val ";
      }
    echo
"</pre>";
?>

Output
E_ERROR=>1
E_RECOVERABLE_ERROR=>4096
E_WARNING=>2
E_PARSE=>4
TRUE=>1
FALSE=>
NULL=>
ZEND_THREAD_SAFE=>1
PHP_VERSION=>5.2.9
PHP_MAJOR_VERSION=>5
PHP_MINOR_VERSION=>2
PHP_RELEASE_VERSION=>9
UPLOAD_ERR_OK=>0
UPLOAD_ERR_INI_SIZE=>1
UPLOAD_ERR_FORM_SIZE=>2
UPLOAD_ERR_PARTIAL=>3
CAL_GREGORIAN=>0
CAL_JULIAN=>1
CAL_JEWISH=>2
CAL_FRENCH=>3
CAL_NUM_CALS=>4
VT_NULL=>1
VT_EMPTY=>0
VT_UI1=>17
VT_I1=>16
VT_UI2=>18
FILTER_FLAG_NONE=>0
FILTER_REQUIRE_SCALAR=>33554432
FILTER_REQUIRE_ARRAY=>16777216
FILTER_FORCE_ARRAY=>67108864
g=>9.8
PI=>31.4

Related Tags for PHP list constants:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.