Post module php introduction
This presentation is the property of its rightful owner.
Sponsored Links
1 / 6

Post-Module PHP Introduction PowerPoint PPT Presentation


  • 45 Views
  • Uploaded on
  • Presentation posted in: General

Post-Module PHP Introduction. BTM 395: Internet Programming. PHP string quoting. ' (single quote): for literal strings with minimal text expansion (\\ and \' only) " (double quote): for flexible strings with expansion of variables and many codes (e.g. \n and \t)

Download Presentation

Post-Module PHP Introduction

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Post module php introduction

Post-Module PHP Introduction

BTM 395: Internet Programming


Php string quoting

PHP string quoting

  • ' (single quote): for literal strings with minimal text expansion (\\ and \' only)

  • " (double quote): for flexible strings with expansion of variables and many codes (e.g. \n and \t)

  • Heredoc: for lengthy strings with complex plain-text format (see http://codepad.org/pzHHK3wH)

    • Begins with <<<ANY_DELIMITER

    • Ends with ANY_DELIMITER; as the only contents of closing line

    • Expands variables similarly to "

    • Advantage: no need to escape ' or "

    • Nowdocformat works like single quote equivalent of heredoc

  • Official reference: http://php.net/manual/en/language.types.string.php


Array indexing

Array indexing

  • ALL arrays in PHP are associative arrays

  • Numeric indices are automatically generated, but the arrays are still fully associative

  • Arrays can have both flexible associative keys and auto-generated numeric keys

  • Official reference: http://www.php.net/manual/en/language.types.array.php


Customized array sorting

Customized array sorting

  • PHP has many built in array sort functions, for sorting by value, by key, and backwards

  • JavaScript only has one very limited built-in sort: lexicographic (strict alphabetic) sort

  • Both have custom sort functions that work similarly

    • JavaScript: myArray.sort(function(a,b){…});

    • PHP:usort($myArray,customSortFunction);customSortFunction(a,b){…};

    • These can sort any kind of array anyway you like, including multidimensional arrays


Other php tips

Other PHP tips

  • Equality and assignment

    = vs == vs ===

  • The ternary (conditional) operator ? :

    • $myVar = $testCondition? $valueIfTrue: $valueIfFalse;

    • Ternary operator exercise

  • Stop an infinite loop in PHP

    • Click the stop or cancel button on your browser to stop the page loading

    • Or just wait 30 seconds or so for a server timeout


Sources

Sources

  • Heredoc example: http://www.tuxradar.com/practicalphp/2/6/3


  • Login