When I use this code,
$views = array();
$views[]=['somevalue'=>'customerview.php'];
$views[]=['anothervalue'=>'ordersview.php'];
I get this,
Array
(
[0] => Array
(
[somevalue] => customerview.php
)
[1] => Array
(
[anothervalue] => ordersview.php
)
)
How can I make it get rid of the initial array without using array_shift or the like? Why is it putting the numerical array in the first place instead of just this,
Array
(
[somevalue] => customerview.php
[anothervalue] => ordersview.php
)
EDIT: How can I use the short syntax for this? Is that possible?
When you do this:
you're saying, "Push another element onto the array, and assign to it the following value:
But this quantity is an array key and an array value. So what you're doing is inserting into your
$views
array a single element that itself contains an array key and array value. This explains the behavior you're seeing.This should give you the results you want:
Or, in shorthand: