Make WordPress Core


Ignore:
Timestamp:
05/24/2021 12:24:14 PM (4 years ago)
Author:
SergeyBiryukov
Message:

General: Some documentation and test improvements for the _wp_array_set():

  • Update the function DocBlock per the documentation standards.
  • Move the unit tests to a more appropriate place.
  • Rename and reorder the tests for consistency with _wp_array_get() tests.

Follow-up to [50958], [50962], [50964].

See #53175, #52625.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r50958 r50965  
    46374637 *     $array = array();
    46384638 *     _wp_array_set( $array, array( 'a', 'b', 'c', 1 );
     4639 *
    46394640 *     $array becomes:
    46404641 *     array(
     
    46464647 *     );
    46474648 *
    4648  * @param array $array   An array that we want to mutate to include a specific value in a path.
    4649  * @param array $path    An array of keys describing the path that we want to mutate.
    4650  * @param mixed $value   The value that will be set.
     4649 * @internal
     4650 *
     4651 * @since 5.8.0
     4652 * @access private
     4653 *
     4654 * @param array $array An array that we want to mutate to include a specific value in a path.
     4655 * @param array $path  An array of keys describing the path that we want to mutate.
     4656 * @param mixed $value The value that will be set.
    46514657 */
    46524658function _wp_array_set( &$array, $path, $value = null ) {
     
    46604666        return;
    46614667    }
     4668
    46624669    $path_length = count( $path );
     4670
    46634671    if ( 0 === $path_length ) {
    46644672        return;
    46654673    }
     4674
    46664675    foreach ( $path as $path_element ) {
    46674676        if (
     
    46834692        $array = &$array[ $path_element ]; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration
    46844693    }
     4694
    46854695    $array[ $path[ $i ] ] = $value;
    46864696}
Note: See TracChangeset for help on using the changeset viewer.