How to splicing an array to insert an array at a specific position?

$custom = Array( Array( 'name' => $name1, 'url' => $url1 ), Array( 'name' => $name_a, 'url' => $url_a ) ); 

I am trying to combine an 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 be next, with the value $sale_bread_elem inserted at position 1 in the array. I do not 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 ) ); 
+8
source share
1 answer

array_splice & shy; Docs contains an array of items to insert. So the call should be

 array_splice($custom, 1, 0, array($bread_elem)); 
+17
source

Source: https://habr.com/ru/post/917775/


All Articles