PHP Operators

What are operators? Things you can execute operations with. PHP has different kinds of operators:

Arithmetic operators

For Mathematical operations. Choose of the following:

  • + Addition
  • – Subtraction: Subtracts a value from a variable
  • * Multiplies
  • / Divides
  • % Modulus: Gives the remaining number when using division
  • ++ Increments
  • – – Decrements

Note: The increment/decrement operators only affect numbers and strings. Arrays, objects and resources are not affected. Decrementing NULL values has no effect too, but incrementing them results in 1.

– by php.net

Assignment Operators

Assigning Values to Variables.

  • = Variable equals number
  • += Adds value to variables (not replaces variable)
  • -= Decrease value from variable
  • *= Multiplies value to variable
  • /= Divides value from variable
  • .= used in strings to concatenate: $j.=$k is equivalent to $j . $k
  • %= Modulus

Comparison Operators

Often used in if statements when comparing 2 items

  • == is equal to // NOTE: Don’t mix up with assignment operator =
  • != is not equal to
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to

Logical Operators

Usually it is used to combine the results of other operators and returns true or false.

  • && and
  • and Low-precedence and
  • || or
  • or Low-precedence or
  • ! not
  • xor Exclusive or
Advertisements

Bash/Shell

Commands
cd: change directory
ls: list directory
ls -l: long (gives additional information about the directory
ls -la: gives even more information, can show you hidden files
cd ~: brings you back to my personal home directory
pwd: shows you where you are right now
cd /: brings you to root directory
cd ..: brings you one directory up
control + c: breaks whatever you’re doing (interrupt)
less and more: allows you to look at stuff –> in less: control + u/d makes it go up/down, /xy lets you find stuff
cp: copy
mv: move
control +a: going back to the beginning of the line
mkdir: makes a directory
sudo: gives you permission when you don’t have permission by default. Basically, whenever a command doesn’t work because the permission is denied, use that and then type in your password to access the computer
drwx stands for: directory (so type of content) – read – write (means you can make changes to it) – execute (means you can execute it)

Important

When you are in a program (Apache, less, vim..) you can’t “scroll” up – you need to use key combinations such as “control + u/d” for moving up/down.

relative vs. absolute paths: / means it’s an absolute path, without it cd will just go relative to where you are now

When you want to copy or move a directory/file, simply type cp/mv followed by the name position where it is right now and after that the position and name where you want to copy or move it.

important directories
etc: holds most config file
var: where you would normally put your webfiles. Also where logfiles are stored.