Skip to content

Commit 60dfb1e

Browse files
authored
Replace use of 'join' function with 'implode'
If a student googles 'join' to learn more they'll just see that it's an alias of implode, and then have to read about implode. https://www.php.net/manual/en/function.join.php Better to just use implode so there's one less step.
1 parent 303c4a4 commit 60dfb1e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

php/lesson2/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ Array
113113
```
114114
Err, wasn't expecting that? The PHP echo command has to convert values to strings to display them. Most of the time it knows what to do, but it doesn't like to second guess you so wants you to be more specific. So actually it's outputted the string `Array` and warned you with the `PHP Notice` line why it's not what you expected. We can use a `var_dump`, or a string function that can tell it how to format the array items. Here's an example:
115115
```php
116-
echo join(", ", [4, 5, 6]);
116+
echo implode(", ", [4, 5, 6]);
117117
```
118118
This tells it to join each element in the array together with a comma, so the output becomes:
119119
```
120120
4, 5, 6
121121
```
122122
You don't have to have items of just one type in an array, you can mix them up. E.g:
123123
```php
124-
echo join(", ", ["odd", "squad", 4, true]); // displays odd, squad, 4, 1
124+
echo implode(", ", ["odd", "squad", 4, true]); // displays odd, squad, 4, 1
125125
```
126126
127127
#### Associative Arrays

0 commit comments

Comments
 (0)