1 / 8

Intro to PHP

Intro to PHP. Coming from Java or C. How to Write PHP. Get a PHP file ( myfile.php ) Add a PHP tag <? php echo “Hello World”; ?> Run with a PHP interpreter (XAMPP is good for Windows). Variables. Declaration not necessary Variables have no type

Download Presentation

Intro to PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to PHP Coming from Java or C

  2. How to Write PHP • Get a PHP file (myfile.php) • Add a PHP tag <?php echo “Hello World”; ?> • Run with a PHP interpreter (XAMPP is good for Windows)

  3. Variables • Declaration not necessary • Variables have no type • All variables are preceded by a dollar sign $myVariable = 1;$myVariable = “Hello”; for($i = 0; $i < 22; $i++) { echo $i;}

  4. String Concatenation • PHP likes to be unique • It likes to use periods instead of pluses$hello = “Hello ”; $world = “World”; echo $hello . $world; echo “Hello ” . “World”;

  5. Conditionals • Just like C and Java … CAKE$condition = true; if($condition && 1 == 1) { echo “Whoohoo”; } else { echo “How did this happen?”; }

  6. Arrays $numbers = array(); $numbers[] = 1; // pushes integer 1 onto array $numbers[] = 2; // pushes integer 2 onto array sizeof($myArray); // returns length of array print_r($myArray); // prints the array for you

  7. Loops • Same for loop as before (while loops work too! WOW!) • Introducing the for each loop: foreach($numbers as $number) { echo “My number is ” . $number; }

  8. Some Coding Hints • Modulus • $i % 10 == 0 if $i is divisible by 10 • $isEven = ($i % 2 == 0); • $isEven = !($i%2); // same thing but shorter • Ternary Operators • echo isEven ? “It’s Even!” : “It’s Not”;

More Related