So, I was designing a function that can take multiple arguments via the spread operator (...$arg)
but it can also take a simple input array.
I want to access the first element of the array with the array_slice() method, but it doesn't work as expected:
// This is what the spread argument passes into the function if it gets a single array
$arg = [
['value1', 'value2', 'valueN'],
];
// Accessing first element via array_slice:
var_export( array_slice($arg, 0, 1) );
Expected result:
array (
0 => 'value1',
1 => 'value2',
2 => 'valueN',
)
The result is basically equal to the input array:
array (
0 =>
array (
0 => 'value1',
1 => 'value2',
2 => 'valueN',
),
)
I know I can just simply access the 0th element ($arg[0]) to get the first item, but I'm curious why array_slice() doesn't work as I would expect. What am I missing here?