Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #### String concatenation in php
  2. Exploring the trade-offs of various levels of granularity.
  3.  
  4. ##### The string concatenation operator
  5. Strings can be concatenated with `.`
  6.  
  7. `$string = $string1 . $string2 . $string3;`
  8.  
  9. ##### String Assignment
  10.  
  11. `.=`
  12.  
  13. `$string .= $string1;`
  14.  
  15. This is the equivalent to
  16. `$string = $string . $string1;`
  17.  
  18. ##### Arrays with delimiters
  19.  
  20. ```
  21. /**
  22. * @var String
  23. * The default delimiter value is an empty string.
  24. * We can set a new default delimiter here.
  25. */
  26.  
  27. $delimiter = ' ';
  28. $array_of_words = ['hello', 'world'];
  29. $string = implode($delimiter, $array_of_words);
  30. ```
  31.  
  32. ##### String indexes
  33.  
  34. This approach provides granularity but increases complexity.
  35.  
  36. ```
  37. foreach ($string1 as $character) {
  38. if ($character > $string2[0]) {
  39. $string .= $character
  40. } else {
  41. $string .= $string2[0];
  42. }
  43. }
  44. ```
  45.  
  46. ```
  47. function parseString($index) use ($string) {
  48. return $string[$index] === $filter;
  49. }
  50. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement