$custom = Array(
Array(
'name' => $name1,
'url' => $url1
),
Array(
'name' => $name_a,
'url' => $url_a
)
);
I am attempting to splice the array with the following:
$bread_elem = array('name' => 'Golf', 'url' => $slug . $parent_slug);
array_splice($custom, 1, 0, $bread_elem);
I want my array to become the following, with the value of $sale_bread_elem
inserted into position one within the array. I can't see what I am doing wrong.
$custom = Array(
Array(
'name' => $name1,
'url' => $url1
),
Array(
'name' => 'Golf',
'url' => $slug . $parent_slug
),
Array(
'name' => $name_a,
'url' => $url_a
)
);
The position specifies the position of the first item to delete and the num argument determines the number of elements to delete. The splice () method changes the original array and returns an array that contains the deleted elements. Let’s take a look at the following example.
Inserting elements using JavaScript array splice. You can insert one or more element into an array by passing three or more arguments to the splice() method with the second argument is zero.
How to Insert an element at a specific position in an Array in Java First get the element to be inserted, say x Then get the position at which this element is to be inserted, say pos Create a new array with the size one greater than the previous size Copy all the elements from previous array into ...
To delete elements in an array, you pass two arguments into the splice () method as follows: The position specifies the position of the first item to delete and the num argument determines the number of elements to delete.
array_splice
Docs takes an array of elements to insert. So the call should actually be
array_splice($custom, 1, 0, array($bread_elem));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With