Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad989ed

Browse files
Merge pull request #480 from bdsl/patch-1
Replace use of 'join' function with 'implode'
2 parents 303c4a4 + 60dfb1e commit ad989ed

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎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)

AltStyle によって変換されたページ (->オリジナル) /