Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### String concatenation in php
- Exploring the trade-offs of various levels of granularity.
- ##### The string concatenation operator
- Strings can be concatenated with `.`
- `$string = $string1 . $string2 . $string3;`
- ##### String Assignment
- `.=`
- `$string .= $string1;`
- This is the equivalent to
- `$string = $string . $string1;`
- ##### Arrays with delimiters
- ```
- /**
- * @var String
- * The default delimiter value is an empty string.
- * We can set a new default delimiter here.
- */
- $delimiter = ' ';
- $array_of_words = ['hello', 'world'];
- $string = implode($delimiter, $array_of_words);
- ```
- ##### String indexes
- This approach provides granularity but increases complexity.
- ```
- foreach ($string1 as $character) {
- if ($character > $string2[0]) {
- $string .= $character
- } else {
- $string .= $string2[0];
- }
- }
- ```
- ```
- function parseString($index) use ($string) {
- return $string[$index] === $filter;
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement