SlideShare a Scribd company logo
Today’s Tools
Write code: http://www.codepad.com
 Select PHP as the language!
Ask questions:
 IRC: irc.freenode.net #php4np
 Twitter: php4np
Robert Ristroph is here for you!
PHP For NonProgrammers
 Programmer: One who writes computer programs.

 NonProgrammer: One who will write PHP code today
 while learning Diana’s Five Rules of Programming
 and earning geek points.




DrupalCon San Francisco 2010
You Win!
Score more than 5 points during today’s
presentation and win the Grand Prize Geek Award*
(GPGA).

* Four Kitchens’ stickers and the right to change your Facebook language to
English(Pirate).
<?php

 /**
  * About Me
  */

 // also comments
 $name = “Diana Montalion Dupuis”;
 $fourKitchensWebChef = TRUE;
 $numPets = 3;

 $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf
 Hall”);

 if ($notWorking == TRUE) {
 
    echo “I’m reading a book or watching football.”;
 } else {
 
    echo “I’m writing PHP code.”;
 }
 ?>


Write your own version!
<?php

 /**                              comments
  * About Me
  */

 // also comments
 $name = “Diana Montalion Dupuis”;
 $fourKitchensWebChef = TRUE;
 $numPets = 3;

 $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf
 Hall”);

 if ($notWorking == TRUE) {
 
    echo “I’m reading a book or watching football.”;
 } else {
 
    echo “I’m writing PHP code.”;
 }
 ?>


Write your own version!
<?php

 /**                              comments
  * About Me
  */

 // also comments
 $name = “Diana Montalion Dupuis”;
 $fourKitchensWebChef = TRUE;                      variables
 $numPets = 3;

 $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf
 Hall”);

 if ($notWorking == TRUE) {
 
    echo “I’m reading a book or watching football.”;
 } else {
 
    echo “I’m writing PHP code.”;
 }
 ?>


Write your own version!
<?php

 /**                              comments
  * About Me
  */

 // also comments
 $name = “Diana Montalion Dupuis”;
 $fourKitchensWebChef = TRUE;                      variables
 $numPets = 3;

 $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf
 Hall”);

 if ($notWorking == TRUE) {
                                                                 array
 
    echo “I’m reading a book or watching football.”;
 } else {
 
    echo “I’m writing PHP code.”;
 }
 ?>


Write your own version!
<?php

 /**                              comments
  * About Me
  */

 // also comments
 $name = “Diana Montalion Dupuis”;
 $fourKitchensWebChef = TRUE;                      variables
 $numPets = 3;

 $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf
 Hall”);

 if ($notWorking == TRUE) {
                                                                 array
 
    echo “I’m reading a book or watching football.”;
 } else {
 
    echo “I’m writing PHP code.”;                      conditional
 }
 ?>


Write your own version!
What does PHP mean?




http://en.wikipedia.org/wiki/PHP
What does PHP mean?
 Who cares?!?




http://en.wikipedia.org/wiki/PHP
What does PHP mean?
 Who cares?!?
 The question and answer that matter most are the




http://en.wikipedia.org/wiki/PHP
What does PHP mean?
 Who cares?!?
 The question and answer that matter most are the

  PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to
  produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server
  with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is
  processed by an interpreter application in command line mode performing desired operating system operations and producing program
  output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern
  web servers and as a standalone interpreter on most operating systems and computing platforms.




http://en.wikipedia.org/wiki/PHP
Diana’s Rule #1




Programming is asking the right questions and coming up with
possible answers.
Diana’s Rule #1
 Self educate constantly.

 Your sixth-grade English teacher was right - if you
 don’t know, look it up. Find places to get help.
 Ignore whatever (or whomever) isn’t helpful.



Programming is asking the right questions and coming up with
possible answers.
I’m a Mac.
Are you a Mac || a PC?



I’m a Mac.
Good Places to Start
Good Places to Start
• W3Schools Tutorial: http://www.w3schools.com/PHP/
Good Places to Start
• W3Schools Tutorial: http://www.w3schools.com/PHP/
• HeadFirst Labs Book: http://headfirstlabs.com/books/
hfphp/
Good Places to Start
• W3Schools Tutorial: http://www.w3schools.com/PHP/
• HeadFirst Labs Book: http://headfirstlabs.com/books/
hfphp/
• PHP.net (and tutorial): http://php.net/manual/en/
tutorial.php
Good Places to Start
• W3Schools Tutorial: http://www.w3schools.com/PHP/
• HeadFirst Labs Book: http://headfirstlabs.com/books/
hfphp/
• PHP.net (and tutorial): http://php.net/manual/en/
tutorial.php
• Pro Drupal Development Book: http://
www.drupalbook.com/
Diana’s Rule #2




How do I get to Carnegie Hall?
Diana’s Rule #2
 Write code.




How do I get to Carnegie Hall?
Diana’s Rule #2
 Write code.

 Writing code is the only thing that teaches you how
 to write code.




How do I get to Carnegie Hall?
Write Code!




I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
Write Code!
  1. Use Codepad or open Notepad (or any other
  simple text program).




I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
Write Code!
  1. Use Codepad or open Notepad (or any other
  simple text program).
  2. Not Microsoft Word, never ever ever use Word. A
  piece of paper and a pen is fine too.




I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
Write Code!
  1. Use Codepad or open Notepad (or any other
  simple text program).
  2. Not Microsoft Word, never ever ever use Word. A
  piece of paper and a pen is fine too.
  2. Write this in the top left-hand corner:




I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
Write Code!




I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
PHP for NonProgrammers (DrupalCon SF 2010)
<?php

/**
 * About Me
 */

$name = “Your Name Here”;

echo $name;

?>
Bonus point if you’ve seen the movie more than 5 times.
$name = “Trinity”;

Bonus point if you’ve seen the movie more than 5 times.
Diana’s Rule #3




“Stupid” mistakes are 85% of mistakes you’ll make.
Diana’s Rule #3
 You will suffer daily from the Missing Semicolon
 Syndrome (MSS).

 Forgetting the semicolon is the most common syntax
 error. PHP errors will break your site. Don’t panic!
 Just fix them.



“Stupid” mistakes are 85% of mistakes you’ll make.
Four PHP Concepts
Four PHP Concepts
• Variables: containers for your stuff
Four PHP Concepts
• Variables: containers for your stuff
• Arrays: a variable that is a list, or a list of lists
Four PHP Concepts
• Variables: containers for your stuff
• Arrays: a variable that is a list, or a list of lists
• Conditionals: the brains of your operation
Four PHP Concepts
• Variables: containers for your stuff
• Arrays: a variable that is a list, or a list of lists
• Conditionals: the brains of your operation
• Functions: little blocks of “do stuff”
Variables
Variables
• begin with the ‘$’ symbol
Variables
• begin with the ‘$’ symbol
• should be aptly named
Variables
• begin with the ‘$’ symbol
• should be aptly named
• come in 8 different flavors
Variables
• begin with the ‘$’ symbol
• should be aptly named
• come in 8 different flavors
• are assigned a value using =
8 Types of Variables
8 Types of Variables
• Boolean: $fourKitchensWebChef = TRUE;
8 Types of Variables
• Boolean: $fourKitchensWebChef = TRUE;
• Integer: $numPets = 3;
8 Types of Variables
• Boolean: $fourKitchensWebChef = TRUE;
• Integer: $numPets = 3;
• Float: $pie = 3.1416;
8 Types of Variables
• Boolean: $fourKitchensWebChef = TRUE;
• Integer: $numPets = 3;
• Float: $pie = 3.1416;
• String: $hobbies = “I enjoy hiking.”;
8 Types of Variables
• Boolean: $fourKitchensWebChef = TRUE;
• Integer: $numPets = 3;
• Float: $pie = 3.1416;
• String: $hobbies = “I enjoy hiking.”;
• Array: $currBooks = array(“The World Without Us”,
“Outliers”, “Brain Rules”, “Wolf Hall”);
And The Rest
And The Rest
Variables we won’t discuss (much) today:
And The Rest
Variables we won’t discuss (much) today:
• Object: $node->id
And The Rest
Variables we won’t discuss (much) today:
• Object: $node->id
• Resource: the database connection, for example
And The Rest
Variables we won’t discuss (much) today:
• Object: $node->id
• Resource: the database connection, for example
• NULL
1 point for the group name, 1 point each for individual
names
$montyPython = array(“TerryG”, “John”,
           “Michael”, “TerryJ”, “Eric”, “Graham”);

1 point for the group name, 1 point each for individual
names
Arrays




array keys start with 0
Arrays
 $myPets = array(“Maya”, “Cloe”, “August”);

 echo $myPets[0];




array keys start with 0
Maya



 Arrays
 $myPets = array(“Maya”, “Cloe”, “August”);

 echo $myPets[0];




array keys start with 0
Foreach is your friend
$myPets = array(“Maya”, “Cloe”, “August”);

foreach ($myPets as $pet) {
  echo $pet;
  echo “<br />”;
}
// $pet is a variable you create
Maya
                  Cloe
                  August


Foreach is your friend
$myPets = array(“Maya”, “Cloe”, “August”);

foreach ($myPets as $pet) {
  echo $pet;
  echo “<br />”;
}
// $pet is a variable you create
Keys and Values
 $actor = array(
   ‘name’ => “John Cleese”,
   ‘nickname’ => “Bruce”,
   ‘job’ => “Minister of Silly Walks”,
 );
 echo $actor[‘nickname’];

this is very common in Drupal coding
Bruce



 Keys and Values
 $actor = array(
   ‘name’ => “John Cleese”,
   ‘nickname’ => “Bruce”,
   ‘job’ => “Minister of Silly Walks”,
 );
 echo $actor[‘nickname’];

this is very common in Drupal coding
<?php

 /**
  * About Me
  */

 $name = “Your Name Here”;


 $yourList = array(“Thing1”, “Thing2”, “Thing3”);

 ?>

Write your own version!
<?php

 /**
  * About Me                    add some
  */                             variables

 $name = “Your Name Here”;


 $yourList = array(“Thing1”, “Thing2”, “Thing3”);

 ?>

Write your own version!
<?php

 /**
  * About Me                             add some
  */                                      variables

 $name = “Your Name Here”;


 $yourList = array(“Thing1”, “Thing2”, “Thing3”);
                          add an array
 ?>

Write your own version!
TRUE || FALSE




Bonus point if you shout “Janeway!”
TRUE || FALSE




Bonus point if you shout “Janeway!”
TRUE || FALSE




Bonus point if you shout “Janeway!”
TRUE || FALSE




                                         TRUE



Bonus point if you shout “Janeway!”
Symbols to Know




More: http://www.w3schools.com/PHP/php_operators.asp
Symbols to Know
 • Assignment: =




More: http://www.w3schools.com/PHP/php_operators.asp
Symbols to Know
 • Assignment: =
 • AND: &&




More: http://www.w3schools.com/PHP/php_operators.asp
Symbols to Know
 • Assignment: =
 • AND: &&
 • OR: ||



More: http://www.w3schools.com/PHP/php_operators.asp
Symbols to Know
 • Assignment: =
 • AND: &&
 • OR: ||
 • Greater and Less Than: > <


More: http://www.w3schools.com/PHP/php_operators.asp
Symbols to Know
 • Assignment: =
 • AND: &&
 • OR: ||
 • Greater and Less Than: > <
 • Is Equal To: ==

More: http://www.w3schools.com/PHP/php_operators.asp
Let’s Talk Boolean
Let’s Talk Boolean
• My name is Diana
Let’s Talk Boolean
• My name is Diana
• My name is Diana && I own a motorcycle
Let’s Talk Boolean
• My name is Diana
• My name is Diana && I own a motorcycle
• My name Diana || I am younger than 29
Let’s Talk Boolean
• My name is Diana
• My name is Diana && I own a motorcycle
• My name Diana || I am younger than 29
• (My name is Diana || I am younger than 29) && I
own a motorcycle
PHP for NonProgrammers (DrupalCon SF 2010)
$myMotorcycle = “BMW F650GS”;
Conditionals are Control
if ($captain == “Picard”) {
  echo “Make it so, Number One.”;
} elseif ($captain == “Kirk”) {
  echo “Two to beam up.”;
} else {
  echo “Please state the nature of your medical
emergency.”;
}
<?php

 /**
  * Boolean Example
  */

 $captain = “Janeway”;

 if ($captain == “Picard”) {
   echo “Make it so, Number One.”;
 } elseif ($captain == “Kirk”) {
   echo “Two to beam up.”;
 } else {
   echo “Please state the nature of your medical emergency.”;

 ?>


There is an MSS issue in this code, can you find it? Hint: }
<?php                                            Please state the nature of your medical
                                                  emergency.
 /**
  * Boolean Example
  */

 $captain = “Janeway”;

 if ($captain == “Picard”) {
   echo “Make it so, Number One.”;
 } elseif ($captain == “Kirk”) {
   echo “Two to beam up.”;
 } else {
   echo “Please state the nature of your medical emergency.”;

 ?>


There is an MSS issue in this code, can you find it? Hint: }
<?php                                            Please state the nature of your medical
                                                  emergency.
 /**
  * Boolean Example
  */

 $captain = “Janeway”;                           MSS ALERT!
 if ($captain == “Picard”) {
   echo “Make it so, Number One.”;
 } elseif ($captain == “Kirk”) {
   echo “Two to beam up.”;
 } else {
   echo “Please state the nature of your medical emergency.”;

 ?>


There is an MSS issue in this code, can you find it? Hint: }
<?php

 /**
  * About Me
  */

 $name = “Your Name Here”;

 $yourList = array(“Thing1”, “Thing2”, “Thing3”);

 if (variable == something && variable == something) {
 
 print “A clever sentence”;
 }

 ?>

Write your own version!
<?php

 /**
  * About Me
  */
                                         variables
 $name = “Your Name Here”;

 $yourList = array(“Thing1”, “Thing2”, “Thing3”);

 if (variable == something && variable == something) {
 
 print “A clever sentence”;
 }

 ?>

Write your own version!
<?php

 /**
  * About Me
  */
                                         variables
 $name = “Your Name Here”;

 $yourList = array(“Thing1”, “Thing2”, “Thing3”);

 if (variable == something && variable == something) {
 
 print “A clever sentence”;
 }
                                add a conditional
 ?>

Write your own version!
A bonus point if you’ve read the book && seen the movie
Hello. My name is Inigo Montoya.
                 You killed my father. Prepare to
                 die.


A bonus point if you’ve read the book && seen the movie
Functions
 Functions encapsulate code that does a specific task.
 The function can be called whenever the task needs
 to be performed.




Tutorial: http://www.tizag.com/phpT/phpfunctions.php
// call the function to count the fingers
$killHim = isSixFingeredMan($numFingers);

if ($killHim) {
   echo “Hello. My name is Inigo Montoya. You killed my
   father. Prepare to die.”;
}

/**
 * Returns true if number of fingers is 6
 */
function isSixFingeredMan($numFingers) {
  if ($numFingers == 6) {
    return TRUE;
  } else {
    return FALSE;
  }
}
// call the function to count the fingers
$killHim = isSixFingeredMan($numFingers);
                                             call
if ($killHim) {
   echo “Hello. My name is Inigo Montoya. You killed my
   father. Prepare to die.”;
}

/**
 * Returns true if number of fingers is 6
 */
function isSixFingeredMan($numFingers) {
  if ($numFingers == 6) {
    return TRUE;
  } else {
    return FALSE;
  }
}
// call the function to count the fingers
$killHim = isSixFingeredMan($numFingers);
                                                call
if ($killHim) {
   echo “Hello. My name is Inigo Montoya. You killed my
   father. Prepare to die.”;
}

/**
 * Returns true if number of fingers is 6
 */
function isSixFingeredMan($numFingers) {
  if ($numFingers == 6) {
    return TRUE;
  } else {                           function
    return FALSE;
  }
}
// call the function to count the fingers
$killHim = isSixFingeredMan($numFingers);
                                                call
if ($killHim) {
   echo “Hello. My name is Inigo Montoya. You killed my
   father. Prepare to die.”;
}                                     continue on
/**
 * Returns true if number of fingers is 6
 */
function isSixFingeredMan($numFingers) {
  if ($numFingers == 6) {
    return TRUE;
  } else {                           function
    return FALSE;
  }
}
Function Facts
Function Facts
• include the word “function”
Function Facts
• include the word “function”
• should be aptly named
Function Facts
• include the word “function”
• should be aptly named
• can accept one or more parameters
Function Facts
• include the word “function”
• should be aptly named
• can accept one or more parameters
• can return something
Function Facts
• include the word “function”
• should be aptly named
• can accept one or more parameters
• can return something
• should be used for repeated tasks and to organize
logic
Function Facts
• include the word “function”
• should be aptly named
• can accept one or more parameters
• can return something
• should be used for repeated tasks and to organize
logic
• can be public or private
<?php

 /**
  * Function Fun
  */

 $yourVariable = “Something”;
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;

 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }

 ?>


Write your own version!
<?php

 /**
  * Function Fun
  */

 $yourVariable = “Something”;                  define a variable
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;

 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }

 ?>


Write your own version!
<?php

 /**
  * Function Fun
  */

 $yourVariable = “Something”;                  define a variable
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;
                                                    call your function
 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }

 ?>


Write your own version!
<?php

 /**
  * Function Fun
  */

 $yourVariable = “Something”;                  define a variable
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;
                                                    call your function
 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }
                                       add a function
 ?>


Write your own version!
<?php

 /**
  * Function Fun
  */

 $yourVariable = “Something”;                  define a variable
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;

 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }
                                       add a function
 ?>


Write your own version!
<?php

 /**
  * Function Fun
  */

 $yourVariable = “Something”;                  define a variable
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;
                                                        continue on
 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }
                                       add a function
 ?>


Write your own version!
<?php                    Here’s a sentence containing Something.
 /**
  * Function Fun
  */

 $yourVariable = “Something”;                    define a variable
 $returnedVariable = NULL;

 $returnedVariable = yourFunction($yourVariable);
 echo $returnedVariable;
                                                         continue on
 public function yourFunction($yourVariable) {
 
 $greeting = “Here’s a sentence containing “. $yourVariable;
 
 return $greeting;
 }
                                        add a function
 ?>


Write your own version!
What does he do for a living?




Score one point for each title you can name
Diana’s Rule #4




Practice makes a programmer.
Diana’s Rule #4
 Read and dissect (good) code.




Practice makes a programmer.
Diana’s Rule #5




http://drupal.org/node/287350
Diana’s Rule #5
 Follow best practices.

 Like the rules of the road, best practices prevent
 (coding) accidents. They also make you a likable
 person.




http://drupal.org/node/287350
Browser Points




Modern Browsers Only!
Browser Points
 • +10: Firefox && (Chrome || Opera)




Modern Browsers Only!
Browser Points
 • +10: Firefox && (Chrome || Opera)
 • +8: Firefox && (IE 7 || IE 8 || Safari)




Modern Browsers Only!
Browser Points
 • +10: Firefox && (Chrome || Opera)
 • +8: Firefox && (IE 7 || IE 8 || Safari)
 • +5: Firefox




Modern Browsers Only!
Browser Points
 • +10: Firefox && (Chrome || Opera)
 • +8: Firefox && (IE 7 || IE 8 || Safari)
 • +5: Firefox
 • +3: IE 7 || IE 8




Modern Browsers Only!
Browser Points
 • +10: Firefox && (Chrome || Opera)
 • +8: Firefox && (IE 7 || IE 8 || Safari)
 • +5: Firefox
 • +3: IE 7 || IE 8
 • +1: Safari



Modern Browsers Only!
Browser Points
 • +10: Firefox && (Chrome || Opera)
 • +8: Firefox && (IE 7 || IE 8 || Safari)
 • +5: Firefox
 • +3: IE 7 || IE 8
 • +1: Safari
 • -3,890,745: IE 6


Modern Browsers Only!
Diana’s Five Rules
 1.   Constantly self educate.
 2.   Write code.
 3.   Accept Missing Semicolon Syndrome gracefully.
 4.   Read and dissect (good) code.
 5.   Follow best practices.




diana@fourkitchens.com
Take the Survey
http://sf2010.drupal.org/conference/schedule

More Related Content

PDF
When your code is nearly old enough to vote
PPTX
PHP Basics and Demo HackU
PDF
Yahoo is open to developers
PPT
Cornell Presentation
PDF
Ruby and Rails by example
KEY
Bestpractices nl
PDF
Empezando con Twig
PDF
Python: with-statement, generators
When your code is nearly old enough to vote
PHP Basics and Demo HackU
Yahoo is open to developers
Cornell Presentation
Ruby and Rails by example
Bestpractices nl
Empezando con Twig
Python: with-statement, generators

What's hot (10)

KEY
PDF
Ruby on Rails Presentation
PPT
Django O/R Mapper
PPT
Best practices in museum search
KEY
Code Fast, Die Young, Throw Structured Exceptions
PDF
Cowboy development with Django
PDF
You Don't Know Query - WordCamp Portland 2011
PPT
Mashup University 4: Intro To Mashups
PDF
Task 1
PDF
Building Things Fast - and getting approval
Ruby on Rails Presentation
Django O/R Mapper
Best practices in museum search
Code Fast, Die Young, Throw Structured Exceptions
Cowboy development with Django
You Don't Know Query - WordCamp Portland 2011
Mashup University 4: Intro To Mashups
Task 1
Building Things Fast - and getting approval
Ad

Viewers also liked (20)

PDF
Don't Design Websites. Design Web SYSTEMS! (DrupalCon Chicago 2011)
KEY
Intro to Drush
PDF
Big Websites for Small Screens: ICANN.org Case Study
PDF
Don't Design Websites. Design Web SYSTEMS! (DrupalCamp LA 2011)
KEY
Teaching Drupal
PPT
Clase parker
PDF
Four Kitchens: We make BIG websites
PDF
Scalable Drupal infrastructure
PDF
Foucault%20y%20 senett[1]
PPT
Horswell x maría josé villanueva
PDF
9. Bell
KEY
Big Websites
PDF
Is Drupal secure?
PDF
3 zizek multiculturalismo o la lógica cultural del capitalismo multinacional
PDF
Accelerated grid theming using NineSixty (DrupalCamp Dallas)
PDF
Accelerated grid theming using NineSixty (Drupal Design Camp Boston 2009)
PDF
UX design for every screen
PDF
Four Kitchens Presents: Future of the CMS
PDF
PowerPoint et mon cours - 5 règles pour une présentation efficace
PDF
Les réseaux sociaux dans votre stratégie de contenu en 10 questions
Don't Design Websites. Design Web SYSTEMS! (DrupalCon Chicago 2011)
Intro to Drush
Big Websites for Small Screens: ICANN.org Case Study
Don't Design Websites. Design Web SYSTEMS! (DrupalCamp LA 2011)
Teaching Drupal
Clase parker
Four Kitchens: We make BIG websites
Scalable Drupal infrastructure
Foucault%20y%20 senett[1]
Horswell x maría josé villanueva
9. Bell
Big Websites
Is Drupal secure?
3 zizek multiculturalismo o la lógica cultural del capitalismo multinacional
Accelerated grid theming using NineSixty (DrupalCamp Dallas)
Accelerated grid theming using NineSixty (Drupal Design Camp Boston 2009)
UX design for every screen
Four Kitchens Presents: Future of the CMS
PowerPoint et mon cours - 5 règles pour une présentation efficace
Les réseaux sociaux dans votre stratégie de contenu en 10 questions
Ad

Similar to PHP for NonProgrammers (DrupalCon SF 2010) (20)

PDF
Zend Certification Preparation Tutorial
ODP
Php 102: Out with the Bad, In with the Good
PDF
Php converted pdf
PPTX
Intro to php
PPT
Php introduction
PPTX
Ch1(introduction to php)
PDF
basic concept of php(Gunikhan sonowal)
PDF
Php Crash Course - Macq Electronique 2010
PPTX
Unit-1 PHP Basic1 of the understanding of php.pptx
PPT
MIND sweeping introduction to PHP
PPTX
Php with mysql ppt
PPTX
PPT
Writing Friendly libraries for CodeIgniter
PPTX
Phphacku iitd
PPTX
PHP for hacks
PPTX
ODP
PHP Basic
Zend Certification Preparation Tutorial
Php 102: Out with the Bad, In with the Good
Php converted pdf
Intro to php
Php introduction
Ch1(introduction to php)
basic concept of php(Gunikhan sonowal)
Php Crash Course - Macq Electronique 2010
Unit-1 PHP Basic1 of the understanding of php.pptx
MIND sweeping introduction to PHP
Php with mysql ppt
Writing Friendly libraries for CodeIgniter
Phphacku iitd
PHP for hacks
PHP Basic

More from Four Kitchens (19)

PDF
Don't Design Websites. Design Web SYSTEMS! (UT Austin Drupal Users Group)
PDF
No RFPs! Why requests for proposal are bad for business (and how we can stop ...
PDF
Don't Design Websites. Design Web SYSTEMS! (BADCamp 2011)
PDF
Don't Design Websites. Design Web SYSTEMS! (DrupalCon London 2011)
PDF
Accelerated grid theming using NineSixty (DrupalCamp LA 2011)
PDF
Don't Design Websites. Design Web SYSTEMS! (Dallas Drupal Days 2011)
KEY
Building Responsive Websites and Apps with Drupal
PDF
Accelerated grid theming using NineSixty (Dallas Drupal Days 2011)
KEY
Designing future proof websites
PDF
Making drupal beautiful with web fonts
PDF
The type revolutionary's cookbook
PDF
The Web Chef Cookbook
PDF
Don't Design Websites. Design Web SYSTEMS! (DrupalCamp Stockholm 2011)
PDF
Don't Design Websites. Design Web SYSTEMS! (DrupalCon Copenhagen 2010)
KEY
The state of web typography
PDF
Accelerated grid theming using NineSixty (Drupal Design Camp Boston 2010)
PDF
From Photoshop to Drupal Theme (DrupalCon San Francisco 2010)
PDF
Accelerated grid theming using NineSixty (DrupalCon San Francisco 2010)
PDF
Drupal theming using the 960.gs grid system
Don't Design Websites. Design Web SYSTEMS! (UT Austin Drupal Users Group)
No RFPs! Why requests for proposal are bad for business (and how we can stop ...
Don't Design Websites. Design Web SYSTEMS! (BADCamp 2011)
Don't Design Websites. Design Web SYSTEMS! (DrupalCon London 2011)
Accelerated grid theming using NineSixty (DrupalCamp LA 2011)
Don't Design Websites. Design Web SYSTEMS! (Dallas Drupal Days 2011)
Building Responsive Websites and Apps with Drupal
Accelerated grid theming using NineSixty (Dallas Drupal Days 2011)
Designing future proof websites
Making drupal beautiful with web fonts
The type revolutionary's cookbook
The Web Chef Cookbook
Don't Design Websites. Design Web SYSTEMS! (DrupalCamp Stockholm 2011)
Don't Design Websites. Design Web SYSTEMS! (DrupalCon Copenhagen 2010)
The state of web typography
Accelerated grid theming using NineSixty (Drupal Design Camp Boston 2010)
From Photoshop to Drupal Theme (DrupalCon San Francisco 2010)
Accelerated grid theming using NineSixty (DrupalCon San Francisco 2010)
Drupal theming using the 960.gs grid system

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PPTX
A Presentation on Artificial Intelligence
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Modernizing your data center with Dell and AMD
NewMind AI Monthly Chronicles - July 2025
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
Review of recent advances in non-invasive hemoglobin estimation
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
A Presentation on Artificial Intelligence
CIFDAQ's Market Insight: SEC Turns Pro Crypto
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf

PHP for NonProgrammers (DrupalCon SF 2010)

  • 1. Today’s Tools Write code: http://www.codepad.com Select PHP as the language! Ask questions: IRC: irc.freenode.net #php4np Twitter: php4np Robert Ristroph is here for you!
  • 2. PHP For NonProgrammers Programmer: One who writes computer programs. NonProgrammer: One who will write PHP code today while learning Diana’s Five Rules of Programming and earning geek points. DrupalCon San Francisco 2010
  • 3. You Win! Score more than 5 points during today’s presentation and win the Grand Prize Geek Award* (GPGA). * Four Kitchens’ stickers and the right to change your Facebook language to English(Pirate).
  • 4. <?php /** * About Me */ // also comments $name = “Diana Montalion Dupuis”; $fourKitchensWebChef = TRUE; $numPets = 3; $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf Hall”); if ($notWorking == TRUE) { echo “I’m reading a book or watching football.”; } else { echo “I’m writing PHP code.”; } ?> Write your own version!
  • 5. <?php /** comments * About Me */ // also comments $name = “Diana Montalion Dupuis”; $fourKitchensWebChef = TRUE; $numPets = 3; $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf Hall”); if ($notWorking == TRUE) { echo “I’m reading a book or watching football.”; } else { echo “I’m writing PHP code.”; } ?> Write your own version!
  • 6. <?php /** comments * About Me */ // also comments $name = “Diana Montalion Dupuis”; $fourKitchensWebChef = TRUE; variables $numPets = 3; $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf Hall”); if ($notWorking == TRUE) { echo “I’m reading a book or watching football.”; } else { echo “I’m writing PHP code.”; } ?> Write your own version!
  • 7. <?php /** comments * About Me */ // also comments $name = “Diana Montalion Dupuis”; $fourKitchensWebChef = TRUE; variables $numPets = 3; $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf Hall”); if ($notWorking == TRUE) { array echo “I’m reading a book or watching football.”; } else { echo “I’m writing PHP code.”; } ?> Write your own version!
  • 8. <?php /** comments * About Me */ // also comments $name = “Diana Montalion Dupuis”; $fourKitchensWebChef = TRUE; variables $numPets = 3; $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf Hall”); if ($notWorking == TRUE) { array echo “I’m reading a book or watching football.”; } else { echo “I’m writing PHP code.”; conditional } ?> Write your own version!
  • 9. What does PHP mean? http://en.wikipedia.org/wiki/PHP
  • 10. What does PHP mean? Who cares?!? http://en.wikipedia.org/wiki/PHP
  • 11. What does PHP mean? Who cares?!? The question and answer that matter most are the http://en.wikipedia.org/wiki/PHP
  • 12. What does PHP mean? Who cares?!? The question and answer that matter most are the PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as a standalone interpreter on most operating systems and computing platforms. http://en.wikipedia.org/wiki/PHP
  • 13. Diana’s Rule #1 Programming is asking the right questions and coming up with possible answers.
  • 14. Diana’s Rule #1 Self educate constantly. Your sixth-grade English teacher was right - if you don’t know, look it up. Find places to get help. Ignore whatever (or whomever) isn’t helpful. Programming is asking the right questions and coming up with possible answers.
  • 16. Are you a Mac || a PC? I’m a Mac.
  • 17. Good Places to Start
  • 18. Good Places to Start • W3Schools Tutorial: http://www.w3schools.com/PHP/
  • 19. Good Places to Start • W3Schools Tutorial: http://www.w3schools.com/PHP/ • HeadFirst Labs Book: http://headfirstlabs.com/books/ hfphp/
  • 20. Good Places to Start • W3Schools Tutorial: http://www.w3schools.com/PHP/ • HeadFirst Labs Book: http://headfirstlabs.com/books/ hfphp/ • PHP.net (and tutorial): http://php.net/manual/en/ tutorial.php
  • 21. Good Places to Start • W3Schools Tutorial: http://www.w3schools.com/PHP/ • HeadFirst Labs Book: http://headfirstlabs.com/books/ hfphp/ • PHP.net (and tutorial): http://php.net/manual/en/ tutorial.php • Pro Drupal Development Book: http:// www.drupalbook.com/
  • 22. Diana’s Rule #2 How do I get to Carnegie Hall?
  • 23. Diana’s Rule #2 Write code. How do I get to Carnegie Hall?
  • 24. Diana’s Rule #2 Write code. Writing code is the only thing that teaches you how to write code. How do I get to Carnegie Hall?
  • 25. Write Code! I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
  • 26. Write Code! 1. Use Codepad or open Notepad (or any other simple text program). I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
  • 27. Write Code! 1. Use Codepad or open Notepad (or any other simple text program). 2. Not Microsoft Word, never ever ever use Word. A piece of paper and a pen is fine too. I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
  • 28. Write Code! 1. Use Codepad or open Notepad (or any other simple text program). 2. Not Microsoft Word, never ever ever use Word. A piece of paper and a pen is fine too. 2. Write this in the top left-hand corner: I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
  • 29. Write Code! I recommend TextMate and Coda for Mac, EditPlus and Aptana for PCs
  • 31. <?php /** * About Me */ $name = “Your Name Here”; echo $name; ?>
  • 32. Bonus point if you’ve seen the movie more than 5 times.
  • 33. $name = “Trinity”; Bonus point if you’ve seen the movie more than 5 times.
  • 34. Diana’s Rule #3 “Stupid” mistakes are 85% of mistakes you’ll make.
  • 35. Diana’s Rule #3 You will suffer daily from the Missing Semicolon Syndrome (MSS). Forgetting the semicolon is the most common syntax error. PHP errors will break your site. Don’t panic! Just fix them. “Stupid” mistakes are 85% of mistakes you’ll make.
  • 37. Four PHP Concepts • Variables: containers for your stuff
  • 38. Four PHP Concepts • Variables: containers for your stuff • Arrays: a variable that is a list, or a list of lists
  • 39. Four PHP Concepts • Variables: containers for your stuff • Arrays: a variable that is a list, or a list of lists • Conditionals: the brains of your operation
  • 40. Four PHP Concepts • Variables: containers for your stuff • Arrays: a variable that is a list, or a list of lists • Conditionals: the brains of your operation • Functions: little blocks of “do stuff”
  • 42. Variables • begin with the ‘$’ symbol
  • 43. Variables • begin with the ‘$’ symbol • should be aptly named
  • 44. Variables • begin with the ‘$’ symbol • should be aptly named • come in 8 different flavors
  • 45. Variables • begin with the ‘$’ symbol • should be aptly named • come in 8 different flavors • are assigned a value using =
  • 46. 8 Types of Variables
  • 47. 8 Types of Variables • Boolean: $fourKitchensWebChef = TRUE;
  • 48. 8 Types of Variables • Boolean: $fourKitchensWebChef = TRUE; • Integer: $numPets = 3;
  • 49. 8 Types of Variables • Boolean: $fourKitchensWebChef = TRUE; • Integer: $numPets = 3; • Float: $pie = 3.1416;
  • 50. 8 Types of Variables • Boolean: $fourKitchensWebChef = TRUE; • Integer: $numPets = 3; • Float: $pie = 3.1416; • String: $hobbies = “I enjoy hiking.”;
  • 51. 8 Types of Variables • Boolean: $fourKitchensWebChef = TRUE; • Integer: $numPets = 3; • Float: $pie = 3.1416; • String: $hobbies = “I enjoy hiking.”; • Array: $currBooks = array(“The World Without Us”, “Outliers”, “Brain Rules”, “Wolf Hall”);
  • 53. And The Rest Variables we won’t discuss (much) today:
  • 54. And The Rest Variables we won’t discuss (much) today: • Object: $node->id
  • 55. And The Rest Variables we won’t discuss (much) today: • Object: $node->id • Resource: the database connection, for example
  • 56. And The Rest Variables we won’t discuss (much) today: • Object: $node->id • Resource: the database connection, for example • NULL
  • 57. 1 point for the group name, 1 point each for individual names
  • 58. $montyPython = array(“TerryG”, “John”, “Michael”, “TerryJ”, “Eric”, “Graham”); 1 point for the group name, 1 point each for individual names
  • 60. Arrays $myPets = array(“Maya”, “Cloe”, “August”); echo $myPets[0]; array keys start with 0
  • 61. Maya Arrays $myPets = array(“Maya”, “Cloe”, “August”); echo $myPets[0]; array keys start with 0
  • 62. Foreach is your friend $myPets = array(“Maya”, “Cloe”, “August”); foreach ($myPets as $pet) { echo $pet; echo “<br />”; } // $pet is a variable you create
  • 63. Maya Cloe August Foreach is your friend $myPets = array(“Maya”, “Cloe”, “August”); foreach ($myPets as $pet) { echo $pet; echo “<br />”; } // $pet is a variable you create
  • 64. Keys and Values $actor = array( ‘name’ => “John Cleese”, ‘nickname’ => “Bruce”, ‘job’ => “Minister of Silly Walks”, ); echo $actor[‘nickname’]; this is very common in Drupal coding
  • 65. Bruce Keys and Values $actor = array( ‘name’ => “John Cleese”, ‘nickname’ => “Bruce”, ‘job’ => “Minister of Silly Walks”, ); echo $actor[‘nickname’]; this is very common in Drupal coding
  • 66. <?php /** * About Me */ $name = “Your Name Here”; $yourList = array(“Thing1”, “Thing2”, “Thing3”); ?> Write your own version!
  • 67. <?php /** * About Me add some */ variables $name = “Your Name Here”; $yourList = array(“Thing1”, “Thing2”, “Thing3”); ?> Write your own version!
  • 68. <?php /** * About Me add some */ variables $name = “Your Name Here”; $yourList = array(“Thing1”, “Thing2”, “Thing3”); add an array ?> Write your own version!
  • 69. TRUE || FALSE Bonus point if you shout “Janeway!”
  • 70. TRUE || FALSE Bonus point if you shout “Janeway!”
  • 71. TRUE || FALSE Bonus point if you shout “Janeway!”
  • 72. TRUE || FALSE TRUE Bonus point if you shout “Janeway!”
  • 73. Symbols to Know More: http://www.w3schools.com/PHP/php_operators.asp
  • 74. Symbols to Know • Assignment: = More: http://www.w3schools.com/PHP/php_operators.asp
  • 75. Symbols to Know • Assignment: = • AND: && More: http://www.w3schools.com/PHP/php_operators.asp
  • 76. Symbols to Know • Assignment: = • AND: && • OR: || More: http://www.w3schools.com/PHP/php_operators.asp
  • 77. Symbols to Know • Assignment: = • AND: && • OR: || • Greater and Less Than: > < More: http://www.w3schools.com/PHP/php_operators.asp
  • 78. Symbols to Know • Assignment: = • AND: && • OR: || • Greater and Less Than: > < • Is Equal To: == More: http://www.w3schools.com/PHP/php_operators.asp
  • 80. Let’s Talk Boolean • My name is Diana
  • 81. Let’s Talk Boolean • My name is Diana • My name is Diana && I own a motorcycle
  • 82. Let’s Talk Boolean • My name is Diana • My name is Diana && I own a motorcycle • My name Diana || I am younger than 29
  • 83. Let’s Talk Boolean • My name is Diana • My name is Diana && I own a motorcycle • My name Diana || I am younger than 29 • (My name is Diana || I am younger than 29) && I own a motorcycle
  • 86. Conditionals are Control if ($captain == “Picard”) { echo “Make it so, Number One.”; } elseif ($captain == “Kirk”) { echo “Two to beam up.”; } else { echo “Please state the nature of your medical emergency.”; }
  • 87. <?php /** * Boolean Example */ $captain = “Janeway”; if ($captain == “Picard”) { echo “Make it so, Number One.”; } elseif ($captain == “Kirk”) { echo “Two to beam up.”; } else { echo “Please state the nature of your medical emergency.”; ?> There is an MSS issue in this code, can you find it? Hint: }
  • 88. <?php Please state the nature of your medical emergency. /** * Boolean Example */ $captain = “Janeway”; if ($captain == “Picard”) { echo “Make it so, Number One.”; } elseif ($captain == “Kirk”) { echo “Two to beam up.”; } else { echo “Please state the nature of your medical emergency.”; ?> There is an MSS issue in this code, can you find it? Hint: }
  • 89. <?php Please state the nature of your medical emergency. /** * Boolean Example */ $captain = “Janeway”; MSS ALERT! if ($captain == “Picard”) { echo “Make it so, Number One.”; } elseif ($captain == “Kirk”) { echo “Two to beam up.”; } else { echo “Please state the nature of your medical emergency.”; ?> There is an MSS issue in this code, can you find it? Hint: }
  • 90. <?php /** * About Me */ $name = “Your Name Here”; $yourList = array(“Thing1”, “Thing2”, “Thing3”); if (variable == something && variable == something) { print “A clever sentence”; } ?> Write your own version!
  • 91. <?php /** * About Me */ variables $name = “Your Name Here”; $yourList = array(“Thing1”, “Thing2”, “Thing3”); if (variable == something && variable == something) { print “A clever sentence”; } ?> Write your own version!
  • 92. <?php /** * About Me */ variables $name = “Your Name Here”; $yourList = array(“Thing1”, “Thing2”, “Thing3”); if (variable == something && variable == something) { print “A clever sentence”; } add a conditional ?> Write your own version!
  • 93. A bonus point if you’ve read the book && seen the movie
  • 94. Hello. My name is Inigo Montoya. You killed my father. Prepare to die. A bonus point if you’ve read the book && seen the movie
  • 95. Functions Functions encapsulate code that does a specific task. The function can be called whenever the task needs to be performed. Tutorial: http://www.tizag.com/phpT/phpfunctions.php
  • 96. // call the function to count the fingers $killHim = isSixFingeredMan($numFingers); if ($killHim) { echo “Hello. My name is Inigo Montoya. You killed my father. Prepare to die.”; } /** * Returns true if number of fingers is 6 */ function isSixFingeredMan($numFingers) { if ($numFingers == 6) { return TRUE; } else { return FALSE; } }
  • 97. // call the function to count the fingers $killHim = isSixFingeredMan($numFingers); call if ($killHim) { echo “Hello. My name is Inigo Montoya. You killed my father. Prepare to die.”; } /** * Returns true if number of fingers is 6 */ function isSixFingeredMan($numFingers) { if ($numFingers == 6) { return TRUE; } else { return FALSE; } }
  • 98. // call the function to count the fingers $killHim = isSixFingeredMan($numFingers); call if ($killHim) { echo “Hello. My name is Inigo Montoya. You killed my father. Prepare to die.”; } /** * Returns true if number of fingers is 6 */ function isSixFingeredMan($numFingers) { if ($numFingers == 6) { return TRUE; } else { function return FALSE; } }
  • 99. // call the function to count the fingers $killHim = isSixFingeredMan($numFingers); call if ($killHim) { echo “Hello. My name is Inigo Montoya. You killed my father. Prepare to die.”; } continue on /** * Returns true if number of fingers is 6 */ function isSixFingeredMan($numFingers) { if ($numFingers == 6) { return TRUE; } else { function return FALSE; } }
  • 101. Function Facts • include the word “function”
  • 102. Function Facts • include the word “function” • should be aptly named
  • 103. Function Facts • include the word “function” • should be aptly named • can accept one or more parameters
  • 104. Function Facts • include the word “function” • should be aptly named • can accept one or more parameters • can return something
  • 105. Function Facts • include the word “function” • should be aptly named • can accept one or more parameters • can return something • should be used for repeated tasks and to organize logic
  • 106. Function Facts • include the word “function” • should be aptly named • can accept one or more parameters • can return something • should be used for repeated tasks and to organize logic • can be public or private
  • 107. <?php /** * Function Fun */ $yourVariable = “Something”; $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } ?> Write your own version!
  • 108. <?php /** * Function Fun */ $yourVariable = “Something”; define a variable $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } ?> Write your own version!
  • 109. <?php /** * Function Fun */ $yourVariable = “Something”; define a variable $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; call your function public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } ?> Write your own version!
  • 110. <?php /** * Function Fun */ $yourVariable = “Something”; define a variable $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; call your function public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } add a function ?> Write your own version!
  • 111. <?php /** * Function Fun */ $yourVariable = “Something”; define a variable $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } add a function ?> Write your own version!
  • 112. <?php /** * Function Fun */ $yourVariable = “Something”; define a variable $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; continue on public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } add a function ?> Write your own version!
  • 113. <?php Here’s a sentence containing Something. /** * Function Fun */ $yourVariable = “Something”; define a variable $returnedVariable = NULL; $returnedVariable = yourFunction($yourVariable); echo $returnedVariable; continue on public function yourFunction($yourVariable) { $greeting = “Here’s a sentence containing “. $yourVariable; return $greeting; } add a function ?> Write your own version!
  • 114. What does he do for a living? Score one point for each title you can name
  • 115. Diana’s Rule #4 Practice makes a programmer.
  • 116. Diana’s Rule #4 Read and dissect (good) code. Practice makes a programmer.
  • 118. Diana’s Rule #5 Follow best practices. Like the rules of the road, best practices prevent (coding) accidents. They also make you a likable person. http://drupal.org/node/287350
  • 120. Browser Points • +10: Firefox && (Chrome || Opera) Modern Browsers Only!
  • 121. Browser Points • +10: Firefox && (Chrome || Opera) • +8: Firefox && (IE 7 || IE 8 || Safari) Modern Browsers Only!
  • 122. Browser Points • +10: Firefox && (Chrome || Opera) • +8: Firefox && (IE 7 || IE 8 || Safari) • +5: Firefox Modern Browsers Only!
  • 123. Browser Points • +10: Firefox && (Chrome || Opera) • +8: Firefox && (IE 7 || IE 8 || Safari) • +5: Firefox • +3: IE 7 || IE 8 Modern Browsers Only!
  • 124. Browser Points • +10: Firefox && (Chrome || Opera) • +8: Firefox && (IE 7 || IE 8 || Safari) • +5: Firefox • +3: IE 7 || IE 8 • +1: Safari Modern Browsers Only!
  • 125. Browser Points • +10: Firefox && (Chrome || Opera) • +8: Firefox && (IE 7 || IE 8 || Safari) • +5: Firefox • +3: IE 7 || IE 8 • +1: Safari • -3,890,745: IE 6 Modern Browsers Only!
  • 126. Diana’s Five Rules 1. Constantly self educate. 2. Write code. 3. Accept Missing Semicolon Syndrome gracefully. 4. Read and dissect (good) code. 5. Follow best practices. diana@fourkitchens.com