Skip to content

Instantly share code, notes, and snippets.

@recck
recck / lec02.php
Created August 22, 2012 01:58
Week 1 - Day 2 - PHP Syntax, Variables and Mathematical Operations
<?php
/**
* Mathematical Operations
* Addition, +, 5+2 = 7
* Subtraction, -, 5-2 = 3
* Multiplication, *, 5*2 = 10
* Division, /, 5/2 = 2.5
* Modulus, %, 5%2 = 1
*
* Short Hand Operations
@recck
recck / logic.php
Created August 22, 2012 21:00
Week 2 - Day 3 - Conditional Logic
<?php
/**
* Mathematical Comparison Operators
* x > y, is x greater than y?
* x >= y, is x greater than OR equal to y?
* x < y, is x less than y?
* x <= y, is x less than OR equal to y?
*
* Logical Comparison Operators
* x == y, does x have the same value as y?
@recck
recck / loops.php
Created August 27, 2012 19:56
Week 2 - Day 4 - PHP Loops
<?php
/**
* for loops
* where to start; when to continue; how to step through
**/
for($i = 0; $i < 10; $i++){
// start at i = 0 and continue until i is >= 10
echo $i;
@recck
recck / strings.php
Created September 7, 2012 14:36
Week 3 - Day 5 - Playing with Strings
<?php
/**
* Programming in PHP
* Week 3 - Day 5
* Playing with Strings
**/
/**
* length of a string!
**/
@recck
recck / arrays.php
Created September 11, 2012 13:36
Week 3 - Day 5 - Playing with Arrays
<?php
/**
* Playing with Arrays
* List of functions: http://us2.php.net/manual/en/ref.array.php
**/
// Creating an array
$array = array('value1', 2, 'value3', 4.5);
// Remember an array starts at position 0
@recck
recck / functions.php
Created September 16, 2012 19:50
Week 4 - Day 7 - User Defined Functions
<?php
/**
* Creating our own functions
**/
// Our First Function
function firstFunction(){
return 'Hello buddy, how is it going?';
}
@recck
recck / recursion.php
Created September 18, 2012 01:20
Week 4 - Day 8 - Recursive Functions
<?php
/**
* Recursive Functions
**/
/** Solving a Factorial **/
// Non Recursively
function factorial_NoRecursion($x){
$y = 1;
@recck
recck / get.php
Created September 24, 2012 13:10
Week 5 - Day 9 - Using GET
<?php
/**
* Using GET
**/
// the variable $_GET is an array
print_r($_GET);
// the URL is get.php?page=index
echo $_GET['page']; // index
@recck
recck / post.php
Created September 26, 2012 13:07
Week 5 - Day 10 - Using POST
<?php
/**
* Using POST
**/
// see if any post request has been made
if(count($_POST) > 0){
print_r($_POST);
}
@recck
recck / cookies.php
Created October 7, 2012 16:20
Programming in PHP - Week 6 - Day 11 - Sessions and Cookies
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['name'])){
setcookie('yourName', htmlentities($_POST['name']));
header("Location: cookies.php");
}else {
echo 'Please enter a name!<br />';
}
}