ap_set_in_array( array $arr, string $path, mixed $val, bool $merge_arr = false )
Description #
Set key => value in an array.
Parameters #
- $arrarray (Required) Array in which key value need to set.
- $pathstring (Required) Path of new array item.
- $valmixed (Required) Value to set.
- $merge_arrbool (Optional) Should merge array. Default value: false
Source #
File: includes/functions.php
function ap_set_in_array( &$arr, $path, $val, $merge_arr = false ) { $path = is_string( $path ) ? explode( '.', $path ) : $path; $loc = &$arr; foreach ( (array) $path as $step ) { $loc = &$loc[ $step ]; } if ( $merge_arr && is_array( $loc ) ) { $loc = array_merge( $loc, $val ); } else { $loc = $val; } return $loc; }
Expand full source code Collapse full source code View on GitHub: includes/functions.php:2010
Add your comment