I use this function like you'd use angular.extend() or $.extend() in my controllers.
function extend($base = array(), $replacements = array())
{
$base = !is_array($base) ? array() : $base;
$replacements = !is_array($replacements) ? array() : $replacements;
return array_replace_recursive($base, $replacements);
}
Standard use:
$inputs = extend([
'name' => 'test',
'empty'
], getInputs());
// getInputs() grabs the data from a form encoded or json body request.
I want empty to be a key so I can use this array with Laravel models or other objects later on.
I get:
[
[name] => 'test',
[0] => 'empty'
]
I want:
[
[name] => 'test',
[empty] => null
]
This should output: OK (1 test, 2 assertions)
public function testInputs()
{
$inputs = \Api::inputs([
'name' => 'test',
'empty'
]);
$this->assertArrayHasKey('name', $inputs);
$this->assertArrayHasKey('empty', $inputs);
}
Is there a native way to do this or will I be rolling my own?
emptyis a value in your input array. You expect that function to change it to a key?