Beginning PHP      Session #2    October 6, 2011      Josh Butts
Agenda for TodayGo over Homework #1Control StructuresInclude & RequireString Functions
Control StructuresIf - Else statementsTernary OperatorSwitch StatementsLoops
If Statements
Switch Statements
Ternary - A Special If-Else   Shorthand for an IF statement with exactly one else condition   Returns a value to a variabl...
LoopsAnother core language function that is used repetitively (Ha!)Types   For   Foreach (remember this one)   WhileLoops ...
For Loops
Foreach, the mightiest loop
While - The Boolean Loop
String FunctionsYou’ll use these all the timeThe internet deals in stringsMuch like array functions, there are quite a few
strlen()   How long is a string, in characters?
substr()   Get a smaller part of the whole string
str_replace()   search and replace strings within strings   use arrays for extra power
strpos()   Finds out the “index” location of a string within a string   Commonly used to find if a string exists within ano...
Changing Case
explode()   Split up a string on certain characters and give   back an array of the pieces
implode()   Build a string from an array
IncludeLoad another PHP file into the current contextsExecutes that code as if it were in the current fileGives a warning if...
Include_OnceThe same as include, except keeps track of if you’re alreadyincluded the file and only includes it onceUse but ...
RequireFunctions the same way as include except gives a fatal errorif the file is not foundTends to be used for system comp...
Upcoming SlideShare
Loading in …5
×

Fall 2011 PHP Class - Session 2

804 views
759 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
804
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Fall 2011 PHP Class - Session 2

    1. 1. Beginning PHP Session #2 October 6, 2011 Josh Butts
    2. 2. Agenda for TodayGo over Homework #1Control StructuresInclude & RequireString Functions
    3. 3. Control StructuresIf - Else statementsTernary OperatorSwitch StatementsLoops
    4. 4. If Statements
    5. 5. Switch Statements
    6. 6. Ternary - A Special If-Else Shorthand for an IF statement with exactly one else condition Returns a value to a variable or function rather than running code Any single expression can be interchanged for any of the sections outlined below, including variables, functions, even another ternary
    7. 7. LoopsAnother core language function that is used repetitively (Ha!)Types For Foreach (remember this one) WhileLoops and arrays were meant for each other
    8. 8. For Loops
    9. 9. Foreach, the mightiest loop
    10. 10. While - The Boolean Loop
    11. 11. String FunctionsYou’ll use these all the timeThe internet deals in stringsMuch like array functions, there are quite a few
    12. 12. strlen() How long is a string, in characters?
    13. 13. substr() Get a smaller part of the whole string
    14. 14. str_replace() search and replace strings within strings use arrays for extra power
    15. 15. strpos() Finds out the “index” location of a string within a string Commonly used to find if a string exists within another
    16. 16. Changing Case
    17. 17. explode() Split up a string on certain characters and give back an array of the pieces
    18. 18. implode() Build a string from an array
    19. 19. IncludeLoad another PHP file into the current contextsExecutes that code as if it were in the current fileGives a warning if the file is not found
    20. 20. Include_OnceThe same as include, except keeps track of if you’re alreadyincluded the file and only includes it onceUse but don’t abuse, there is an implicit speed penalty fordoing this
    21. 21. RequireFunctions the same way as include except gives a fatal errorif the file is not foundTends to be used for system components vs. small outputsnippetsRequire_once == include_once

    ×