Share on Google+Share on Google+

PHP list constants

Advertisement
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

Advertisements

Posted on: November 2, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.