PHP inserts an element before the Key specified in the associated array. The array key
This example describes how PHP inserts an element before the Key specified by the associated array. We will share this with you for your reference. The details are as follows:
PHP associated Arrays can be inserted into new elements in three ways:
1.$ Array [$ insert_key] = $ insert_value;
2.$ Array = array_merge ($ array, $ insert_array );
3.$ Array = $ array + $ insert_array;
But what if you want to insert an element before the specified key? The following code inserts $ data into the joined array $ array before the key named $ Key:
Function wpjam_array_push ($ array, $ data = null, $ key = false) {$ data = (array) $ data; $ offset = ($ key = false )? False: array_search ($ key, array_keys ($ array); $ offset = ($ offset )? $ Offset: false; if ($ offset) {return array_merge (array_slice ($ array, 0, $ offset), $ data, array_slice ($ array, $ offset ));} else {// If $ key is not specified or cannot be found, add the return array_merge ($ array, $ data);} to the end );}}