Skip to content

feat: add php solution to lc problem: No.1507 #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions solution/1500-1599/1507.Reformat Date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ func reformatDate(date string) string {
}
```

### **PHP**

```php
class Solution {
/**
* @param String $date
* @return String
*/
function reformatDate($date) {
$arr = explode(" ", $date);
$months = array("Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12");
$year = $arr[2];
$month = $months[$arr[1]];
$day = intval($arr[0]);
if ($day > 0 && $day < 10) $day = "0".$day;
return $year."-".$month."-".$day;
}
}
```

### **...**

```
Expand Down
20 changes: 20 additions & 0 deletions solution/1500-1599/1507.Reformat Date/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ func reformatDate(date string) string {
}
```

### **PHP**

```php
class Solution {
/**
* @param String $date
* @return String
*/
function reformatDate($date) {
$arr = explode(" ", $date);
$months = array("Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12");
$year = $arr[2];
$month = $months[$arr[1]];
$day = intval($arr[0]);
if ($day > 0 && $day < 10) $day = "0".$day;
return $year."-".$month."-".$day;
}
}
```

### **...**

```
Expand Down
15 changes: 15 additions & 0 deletions solution/1500-1599/1507.Reformat Date/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
/**
* @param String $date
* @return String
*/
function reformatDate($date) {
$arr = explode(" ", $date);
$months = array("Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12");
$year = $arr[2];
$month = $months[$arr[1]];
$day = intval($arr[0]);
if ($day > 0 && $day < 10) $day = "0".$day;
return $year."-".$month."-".$day;
}
}