PHP Tutorial : Constants and Variables

Hi,

I didn’t writed here for 3 days because of the holidays stuff, etc. and now I got a little bit of free time to write about php variables and constants. Variables and constants in php are doing almost the same thing, but the aspect who shows very well the difference between those two things in php coding are the way they get created.

Variables are beeing created and printed in this way :

<?php
$newvariable = "something";
print $newvariable;
?>

The constants are defined in the next way :

<?php
define('Constantname', 'constantvalue');

print Constantname;
?>

The is a set of rules for both such as must begin with a letter, doesn’t allow to containt dashes such as “-”, but there is allowed “_”. For more informations please check the official php website.

Thanks!

This entry was posted in Basic PHP and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>