1 / 11

Web Development

Web Development. PHP Consolidation. Content. This week we are going to go over a number of important areas You need to know these well as when you come to add SQL to your php , it starts to look complicated if you don’t know the basics. Includes.

naiya
Télécharger la présentation

Web Development

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. Web Development PHP Consolidation

  2. Content • This week we are going to go over a number of important areas • You need to know these well as when you come to add SQL to your php, it starts to look complicated if you don’t know the basics

  3. Includes • Using the PHP includes function, you can add standard pieces of code • The parser will add the code in the included file as if you had typed the code there yourself • Use the include function inside php contained with the <body> of the page • Note that the php file that is included does not need <html> tags. Why not? • Try out the include demo php file now

  4. Includes • We would use this: • to avoid retyping code that needs repeating between several pages • because changing the included file once is easier than changing multiple instances of the same code in many files

  5. Functions • These are used for similar reasons as for includes – they avoid code duplication • Code duplication is bad (especially from a code maintenance viewpoint) • The can be placed anywhere and called from anywhere in the PHP code • You can pass several values to them, and can pass one value back if you want • Try out the 5 function demo programs

  6. Global variables • Global variables could be used to return several values from a function • Note: the use of global variables should be limited because they are viewed as bad programming practice • We should limit the scope of our variables as much as possible • NOTE: PHP has many built in functions – don’t reinvent the wheel!

  7. Arrays • Arrays are implemented much like any other programming language • They are values mapped by keys stored under a single variable name • In PHP, the keys can be numeric or alphanumeric • PHP has lots of functions to sort arrays • Arrays can be multidimensional • Try out the array test program

  8. Foreach • Often we need to step through an array and do something with each element contained therein • using normal loops, we need to know what index the array starts with and how big it is • Also PHP arrays do not need to use numeric keys! • A simple answer is provided – use foreach • Try out the foreach test program

  9. heredoc • The process of outputting HTML using the echo command is cumbersome because of the problem of using quotation marks • You may like to use heredoc instead • start the heredoc like this EOD<<< • end with this EOD; • You don’t have to use EOD – anything will do • Try out the example programs, heredoc and heredoc1

  10. heredoc • Warning: heredoc is fussy! • Don’t put anything after the <<< on the opening line or after the ; on the closing line • Also, there must be no leading characters whatsoever, not even spaces or tabs on the closing and opening heredoc lines • You can waste a lot of time trying to fix this very simple error!!

  11. print_r • When dealing with arrays, it can be useful to know what values they contain • Use the print_r command to print on the screen what the array contains • This will prove useful when you dot he assignment! • try out the print_r example program

More Related