My Hands Aren’t Short! PHP shorthand operators are amazing! There, I said it. The shorthand operator combines the expression on the right with the assignment operator. The variable that appears on the left-side of the assignment operator needs to appear on the right-hand-side as well in order for you to be able to use the shorthand notation. Let’s take a look at the following code:   <?php $x = 1; $x = $x + 1; echo $x; ?>   PHP assigns the integer value 1 to the variable $x. In the second statement, $x + 1 is evaluated. $x contains

How Many Operators do You Want Already? PHP Array operators are operators that are used on arrays. Who would have guessed? The first operator that we’ll look at is the + operator. You would think that this operator would be used to merge two arrays, taking elements from both arrays and merging them into a new array, but that is not the case.     If you were to output the result of the code above, you would quickly see that the result is:     The + operator creates a new array that combines key/value pairs. Elements with numeric

A String can operate? The PHP string operator, also known as the concatenation operator, allows us to join two strings together. Strings need to be joined for various reasons, such as injecting a variable, or even splitting a long string so that it’s more readable in your IDE. Let’s take a look at the following sentence (string): “I am sick and tired of creating operator tutorials.” We can echo it out or assign it to a variable. We can also split the string up using the concatenation operator and have as many strings as there are characters in it.  

Logic dictates. PHP Logical operators are pretty simple if you’ve taken Boolean Algebra or are familiar with logic-gates. You might have even been exposed to logic in Philosophy. If you’re not familiar with logic, this may be a bit of a shock for you. Only joking. It’s just another operator in our disposal that evaluates to either true or false. We looked at how to test whether an expression is true or not, but how can we test whether multiple expressions are true? With logical operators, that’s how. There are a few operators in PHP that test the truth value

  But I don’t wanna Decrement. PHP increment and decrement operators: these are operators that either add 1 or subtract 1 from the current value. The operators can be prefixed or post-fixed and will yield slightly different results each time. Increment Operator: ++ Decrement Operator: — Normally, to add 1 to a value, you would use the addition operator.   <?php $a = 5; $a = $a + 1; var_dump($a); ?>   In the example above, you evaluate the expression on the right, $a + 1, which becomes 6, and then you assign the value back to $a, on the

  So You Want to Compare Stuff? PHP Comparison Operators, or relational operators, test some type of relation between two values. We’ve seen a few comparison operators in math, such as greater-than and less-than; in PHP, we have a few more comparison operators at our disposal. The relational operators that we’re going to be looking at are: Greater-than: > Greater-than-or-equal-to: ≥ Less-than: < Less-than-or-equal-to: ≤ Equal-to: == Identical-to: === Not-equal-to: != or <> Not-identical-to: !== Spaceship operator: <=> The comparison operator, whichever one you choose, will evaluate to either true or false. If we say, 3 > 2, what we’re

What’s Arithmetic? Arithmetic deals with the study of numbers, especially with operations on those numbers, such as addition, subtraction, multiplication, and division. In mathematics, those operations are called arithmetic operations. Arithmetic operators are then the operators that are used in arithmetic operations. In PHP, we have a few arithmetic operators. They include: addition, subtraction, multiplication, division, modulus, and exponential operators. Let’s just run through the basic ones first. I mean, after all, it is just basic math.   <?php $a = 2 + 2; // $a = 4 $b = 5 – 3; // $b = 2 $c = $a

What do you mean assignment? I thought I was out of school. The assignment operator (=) assigns the value, or expression, to the variable; and yes, it’s different from the equality comparison operator (==). This is one of the most commonly made mistakes for beginner programmers: using the assignment operator when a comparison operator is required. The following syntax is required for the PHP assignment operator:   $variable = value (or expression)   The assignment takes the expression on the right and assigns it to the variable on the left.   <?php // Assign a value to a variable $best_php_tutorial_youtuber

We’re starting to be consistent. PHP Constants are similar to variables except that they cannot change. They can’t change since constants are stored in the read-only-data segment. Why would you not want to keep data constant? A good example is when you want to store database connection information. You do not want to accidentally change the connection information somewhere later in your code and accidentally sever the database connection. How do we define constants in our code? With the define function. define() accepts two arguments: The first argument is the constant name. The second argument is the constant value.  

Variable Variables? Was that a typo? Variable variables: no that’s not a typo. That’s what this topic is about. PHP variable variables are dynamic variables, meaning that you can generate variable names dynamically in PHP. How is this done? If you prepend a dollar sign to a string, the string will then become a variable. Let’s create a regular variable $a. The variable $a will contain the string “bear.” We’ll then create another variable, and this time we’ll add an additional dollar sign before it. We’ll call the new variable variable $$a.   <?php $a = “bear”; $$a = “cow”;