<?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());
preferences:
24.43 ms | 405 KiB | 5 Q