Skip to content

Commit

Permalink
doc: add toLocaleString() documentatio
Browse files Browse the repository at this point in the history
 - Add method description to arr.md
 - Add method use case example to cheatsheet.php
  • Loading branch information
xanaDev committed Oct 16, 2022
1 parent 9ce90cf commit 3e3b87b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/arr.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,23 @@ var_dump($arr->copyWithin(-2, -3, -1));

```

## Return a string representing the elements in the array using a locale and timezone

Default locale is en_US, and the timezone is UTC, in order to use a different locale make sure it is installed.

To check available locales in linux based systems run `locale -a`

To install a missing locale in linux based systems run `sudo apt-get install language-pack-XX`

```php
use HiFolks\DataType\Arr;

$arr = Arr::make([1, 2, 3, 'a', 'abc', 123456.4, "2022/10/01"]);
var_dump($arr->toLocaleString()); // Using en_US as default locale and UTC as default timezone
// 1,2,3,a,abc,123,456.40,Sat 01 Oct 2022 12:00:00 AM UTC

$arr = Arr::make([1, 2, 3, 'a', 'abc', 123456.4, "2022/10/01"]);
var_dump($arr->toLocaleString("fr_FR.utf8", "Europe/Paris")); // Using provided locale and timezone
// [1,2,3,a,abc,123 456,40,sam. 01 oct. 2022 00:00:00]
```

6 changes: 6 additions & 0 deletions examples/cheatsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,9 @@ function print_result(mixed $something): void
print_result($arr->copyWithin(-2, -3, -1));
// [1, 2, 3, 3, 4]
}

// Return a string representing the elements of the array
$arr = Arr::make([1, 2, 3, 'a', 'abc', 123456.4, '2022/10/01']);

print_r($arr->toLocaleString()); // Default locale and timezone
print_r($arr->toLocaleString('fr_FR.utf8', 'Europe/Paris')); // Provided locale and timezone

0 comments on commit 3e3b87b

Please sign in to comment.