<?php
class newsCollection {
private $collection;
private $keys = [
"headline",
"date",
"author",
];
public function __construct($data)
{
foreach ($data as &$el) {
$el = array_combine($this->keys, $el);
}
$this->collection = $data;
}
public function getNewsCollection()
{
return $this->collection;
}
}
$sports = [
[
"Boston Red Sox vs New York Yankees - 9-3",
"19.06.2017",
"ESPN"
],
[
"Boston Patriot QB breaks new record!",
"16.07.2017",
"NESN"
],
[
"Celtics coach John Doe inducted into hall of fame",
"25.07.2017",
"Fox Sports"
],
[
"Boston Brewins win 16-5 against New York's Rangers",
"21.08.2017",
"NESN"
]
];
$c = new newsCollection($sports);
var_dump($c->getNewsCollection());
- Output for 7.0.0 - 7.0.23, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array(4) {
[0]=>
array(3) {
["headline"]=>
string(40) "Boston Red Sox vs New York Yankees - 9-3"
["date"]=>
string(10) "19.06.2017"
["author"]=>
string(4) "ESPN"
}
[1]=>
array(3) {
["headline"]=>
string(36) "Boston Patriot QB breaks new record!"
["date"]=>
string(10) "16.07.2017"
["author"]=>
string(4) "NESN"
}
[2]=>
array(3) {
["headline"]=>
string(49) "Celtics coach John Doe inducted into hall of fame"
["date"]=>
string(10) "25.07.2017"
["author"]=>
string(10) "Fox Sports"
}
[3]=>
array(3) {
["headline"]=>
string(50) "Boston Brewins win 16-5 against New York's Rangers"
["date"]=>
string(10) "21.08.2017"
["author"]=>
string(4) "NESN"
}
}
preferences:
139.66 ms | 410 KiB | 5 Q