SlideServe
Menu
Préférences
© SlideServe · v2026

Mastering Strings and Arrays in PHP

jess avatar
6 diapositives · 193 Views · Aug 07, 2014

Learn about string quoting in PHP using single and double quotes, heredoc, and nowdoc formats. Understand array indexing, sorting, and custom sorting. Explore various PHP tips and tricks for efficient programming.

Mastering Strings and Arrays in PHP - slide 1
01 / 6Mastering Strings and Arrays in PHP
1 / 17

Télécharger la présentation

Mastering Strings and Arrays in PHP
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Post-Module PHP Introduction BTM 395: Internet Programming

  2. 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

  3. 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

  4. 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

  5. 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

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