Example:
$keys = array('id', 'name', 'surname');
$values = array(1, 'john', 'smith');
$combined = Arrays::combine($keys, $values);
Result:
Array
(
[id] => 1
[name] => john
[surname] => smith
)
public static function __callStatic($name, $arguments) { Session::checkSession(); $dynamicFinder = DynamicFinder::match($name); if ($dynamicFinder) { $where = Arrays::combine($dynamicFinder->getNames(), $arguments); return static::where($where); } throw new BadMethodCallException('Method [' . $name . '] not exists'); }
public function setParameters($uri) { $ruleUri = explode('/', $this->getUri()); $requestUri = explode('/', $uri); $filterParameters = FluentArray::from($ruleUri)->filter(function ($parameter) { return preg_match('#:\\w+#', $parameter); })->map(function ($parameter) { return str_replace(':', '', $parameter); })->toArray(); $filterValues = array_intersect_key($requestUri, $filterParameters); $this->parameters = Arrays::combine($filterParameters, $filterValues); }
/** * @test */ public function shouldReturnCombinedArray() { //given $keys = array('id', 'name', 'surname'); $values = array(1, 'john', 'smith'); //when $combined = Arrays::combine($keys, $values); //then Assert::thatArray($combined)->hasSize(3)->containsKeyAndValue(array('id' => 1, 'name' => 'john', 'surname' => 'smith')); }