ap_array_insert_after( array $arr = array(), string $key = '', array $is_new = array() )
Description #
Insert a value or key/value pair after a specific key in an array. If key doesn’t exist, value is appended to the end of the array.
Parameters #
- $arrarray (Optional) Array. Default value: array()
- $keystring (Optional) Key. Default value: ''
- $is_newarray (Optional) Array. Default value: array()
Source #
File: includes/functions.php
function ap_array_insert_after( $arr = array(), $key = '', $is_new = array() ) { $keys = array_keys( $arr ); $index = array_search( $key, $keys ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict $pos = false === $index ? count( $arr ) : $index + 1; return array_merge( array_slice( $arr, 0, $pos ), $is_new, array_slice( $arr, $pos ) ); }
Expand full source code Collapse full source code View on GitHub: includes/functions.php:1966
Add your comment