Follow along:
Created by Juan Manuel Torres / @onema
Born and raised in Bogotá Colombia
Software Engineer
MS Computer Science SDSU, 6+ years of experience
Started using PHP in 2000
Started programming in 1999
What is GitHub?
Computer programs are collections of instructions that tell a computer how to interact with the user, the computer hardware or process data [1]
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development [2]
Unlike other scripting languages that run directly in your computer, PHP will almost always run on a server.
"Hello, World!"
The "Hello, World!" program is the simplest program you can write in any programming language. All it does is output "Hello, World!" [3]
"Hello, World!"
<?php
// THESE ARE COMMENTS AND
// WILL BE IGNORED BY PHP
/*
USE THE "/*" FOR
MULTILINE COMMENTS
*/
print 'Hello, world!';
?>
With our "php-intro-workshop" project there is a sample hello-world.php file
PHP Open tag: tells the computer where the php program starts
PHP only files do not require a closing php tag
A variable is a storage location associated with a name. Variables contain an unknown quantity or information called value [4]
<?php
// 01.simple_variable.php
$name = 'Juan';
$x = 30;
$y = 1.123;
// print the values below
print "";
<?php
// 02.hello_name.php
$name = 'Juan';
print "Hello, $name!";
/**
* This will output:
* Hello, Juan!
*/
A Data Type Is classification identifying one of various types of data [6]
PHP Defines eight data types [7]
<?php
// 03.data_types.php
print gettype(true) . PHP_EOL; // bolean
print gettype(12345) . PHP_EOL; // integer
print gettype(1.2345) . PHP_EOL; // double
print gettype("Hello") . PHP_EOL; // string
print gettype([1, 2, 3]) . PHP_EOL; // array
print gettype(new stdClass()) . PHP_EOL; // object
print gettype(null) . PHP_EOL; // NULL
PHP_EOL is a constant that represents the "End Of Line" symbol.
An operator in a programming language is a symbol that tells the [computer] to perform specific mathematical, relational or logical operation and produce final result. [8]
An operator is something that takes one or more values (or expressions, in programming jargon) and yields another value. [9]
-$a | Negation | Opposite of $a. |
$a + $b | Addition | Sum of $a and $b. |
$a - $b | Subtraction | Difference of $a and $b. |
$a * $b | Multiplication | Product of $a and $b. |
$a / $b | Division | Quotient of $a and $b. |
$a % $b | Modulus | Remainder of $a divided by $b. |
$a ** $b | Exponentiation | Result of raising $a to the $b'th power. |
<?php
// 04.assignment_operator.php
$a = 1;
$b = 2;
$three = $a + $b;
print $three;
The assignment operator "=" is used to assign a value to a variable. It is not used to compare!
$a == $b | Equal | TRUE if $a is equal to $b |
$a === $b | Identical | TRUE if $a is equal to $b |
$a != $b | Not equal | TRUE if $a is not equal to $b |
$a !== $b | Not identical | TRUE if $a is not equal to $b |
$a < $b | Less than | TRUE if $a is strictly less than $b . |
$a > $b | Greater than | TRUE if $a is strictly greater than $b . |
$a <= $b | Less than or equal to | TRUE if $a is less than or equal to $b . |
$a >= $b | Greater than or equal to | TRUE if $a is greater than or equal to $b . |
<?php
// 05.comparison_operators.php
var_dump(1 == 2); // FALSE
var_dump(1 < 2); // TRUE
var_dump(1 <= 2); // TRUE
var_dump(2 > 2); // FALSE
var_dump(2 >= 2); // TRUE
var_dump(1 == true); // TRUE - same as (bool)1 == TRUE
var_dump(1 === true); // FALSE - same as (int)1 === FALSE
var_dump(0 == false); // TRUE - same as (bool)0 == FALSE
var_dump(0 === false); // FALSE - same as (int)0 === FALSE
The assignment operator "=" is used to assign a value to a variable. It is not used to compare!
Write a program that does the following:
Juan Manuel Torres | @onema