What I’m Learning- PHP Constants and Operators

Are you looking to use Constants and Operators in your PHP code? Here is a  collection of some things you will need.

Constants

A constant is something that will not be changed, starts with a letter or _ (no $), and can be used throughout script.

Start here:

define(name, value, case-insensitive)

Name: The name of the constant you are creating

Value: The value of the constant you are creating

Case Insensitive: Default is false (meaning if you want to be case insensitive, don’t fill in this portion)

Unlike strings, constants can be inside or outside functions.


Operators

Perform operations on variables and values (words and numbers) in the following groups:

  • Arithmetic operators
    • Simple math problems
    • <?php
      $x = 10;  
      $y = 6;
      echo $x + $y;
      ?> 
  • Assignment operators
    • using = like “x=y+z”, the x is now equal to the equation
    • <?php
      $x = 20;  
      $x += 100;
      echo $x;
      ?>  
  • Comparison operators
    • are used to compare two values
    •  Got this from W3Schools.com, great site for all languages.
  • Increment/Decrement operators
    • The PHP increment operators are used to increment a variable’s value.

      The PHP decrement operators are used to decrement a variable’s value.

  • Logical operators
  • String operators
  • Array operators

Cheers,

The Code Damsel

 

Leave a Reply

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