$key ) { if ( count( $keys ) === 1 ) { break; } unset( $keys[ $i ] ); // If the key doesn't exist at this depth, we will just create an empty array // to hold the next value, allowing us to create the arrays to hold final // values at the correct depth. Then we'll keep digging into the array. if ( ! isset( $arr[ $key ] ) || ! is_array( $arr[ $key ] ) ) { $arr[ $key ] = array(); } $arr = &$arr[ $key ]; } $arr[ array_shift( $keys ) ] = $value; return $arr; } }