get_defined_constants


php128 apg

Returns an associative ARRAY with the names of all the constants and their values.



<?php

array get_defined_constants bool $categorize false )


where,

$categorize To control the dimension of the returned ARRAY
  
?>

 $categorize 


To control the dimension of the returned ARRAY.

The $categorize cause this function to return a multidimensional array with categories in the keys of the first dimension and constants and their values in the second dimension.


$categorize
BOOL WHAT DOES
FALSE Returns all constant in a uni-dimensional ARRAY.
TRUE Returns a multi-dimensional ARRAY
with categories in the keys of the first dimension
and constants and their values in the second dimension
ed48


These are some constants commonly used in mathematics:


SOME MATHEMATICAL CONSTANTS
NAME CONSTANT PHP notation THE SAME AS...
pi π M_PI  
pi/2 π/2 M_PI_2  
pi/4 π/4 M_PI_4  
1/pi 1/π M_1_PI  
2/pi 2/π M_2_PI  
pi -2 π -2 M_SQRTPI sqrt(M_PI)
2/pi -2 2/π -2 M_2_SQRTPI  
  2 -2 M_SQRT2 sqrt(2)
  (1/2) -2 M_SQRT1_2  
Euler e M_E  
  lg e M_LOG2E ln e
  log e M_LOG10E  
  lg 2 M_LN2 ln 2
  lg 10 M_LN10 ln 10
ed48

SOME MATHEMATICAL CONSTANTS
NAME CONSTANT PHP notation VALUE
pi π M_PI 3.1415926535898
pi/2 π/2 M_PI_2 1.5707963267949
pi/4 π/4 M_PI_4 0.78539816339745
1/pi 1/π M_1_PI 0.31830988618379
2/pi 2/π M_2_PI 0.63661977236758
pi-2 π-2 M_SQRTPI 1.7724538509055
2/pi-2 2/π-2 M_2_SQRTPI 1.1283791670955
  2-2 M_SQRT2 1.4142135623731
  (1/2)-2 M_SQRT1_2 0.70710678118655
Euler e M_E 2.718281828459
  lg e M_LOG2E 1.442695040889
  log e M_LOG10E 0.43429448190325
  lg 2 M_LN2 0.69314718055995
  lg 10 M_LN10 2.302585092994
ed48


This function returns the names and values of all the constants currently defined.

This includes those created by extensions as well as those created with the define function.


  1 EXERCISE   

<?php 

setlocale
(LC_ALL'pt-BR''pt_BR'); 

$ver 'PHP ' PHP_VERSION

if(
PHP_MAJOR_VERSION <= 7)
{
    
$comp '<br>SOME CONSTANTS ARE COMPATIBLES WITH THE LOCALE';
}
else
{
    
$comp '';
}
?>

<table align="center" width="100%" cellspacing="5" 
cellpadding="5" border="1">
<tbody>
<tr>
<td>CONSTANT NAME<br><?php echo $ver $comp?></td> 
<td width="10%">VALUE</td>
</tr> 
<?php

$str01 
get_defined_constants();

foreach(
$str01 as $vl01 => $x01)
{
    echo 
'<tr><td>' $vl01 '</td><td>' $x01 '</td></tr>';
    }

?>
<tr><td colspan="2">ed48</td></tbody></tr></table>


  2 EXERCISE   

<?php 

setlocale
(LC_ALL'de-DE''de_DE'); 

$ver 'PHP ' PHP_VERSION

if(
PHP_MAJOR_VERSION <= 7)
{
    echo 
$ver '<br>SOME CONSTANTS ARE COMPATIBLES WITH THE LOCALE<br><br>';
}
else
{
    echo 
$ver '<br><br>';
}

$arr02 get_defined_constants();

echo 
'<pre>';
print_r($arr02);
echo 
'</pre>';

?>

  3 EXERCISE   

<?php

setlocale
(LC_ALL'es_ES''es-ES'); 

$ver 'PHP ' PHP_VERSION

if(
PHP_MAJOR_VERSION <= 7)
{
    echo 
$ver '<br>SOME CONSTANTS ARE 
             COMPATIBLES WITH LOCALE<br><br>'
;
}
else
{
    echo 
$ver '<br>SOME CONSTANTS 
                ARE NO MORE COMPATIBLES WITH THE LOCALE<br><br>'
;
}

$arr03 get_defined_constants(TRUE);

echo 
'<pre>';
print_r($arr03);
echo 
'</pre>';

?>