PHP

Running

See setup and AMP notes, need the server

Basics

<?php
  //code here
  $my_name = "JJ";
  print($my_name);
    print "Hi"
?>
<div> body </div>
  • dynamically typed language

  • All variable names begin with a $ followed by letters digits or underscores

Printing

  • echo //no return type

  • print //return true always

  • if you use (), only one argument

  • should do $s." ".$t

Functions

  • Function names are not case sensitive

  • & in function def is pass by reference

  • javascript scoping for functions not {}

  • global declaration global $x makes it Avaliable everywhere

Strings

Arrays

Basically dictionaries that if not set use numeric indexes

Functions to call on arrays

  • unset //entry or entire array

  • count OR sizeof

  • is_array

Control

  • if and then like C++, switch statement

    Loops

  • while, for

Big Project Functions

  • isset($x)

  • gettype($x)

Includes

include("filename")

  • check

ERRORS

Do not put a space between #!/usr/local/bin/php <?php ?>

Last updated