PluginProbe
Gutenberg / 8.9.1
Gutenberg v8.9.1
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / utils.php

utils.php in Gutenberg 8.9.1, at lib/utils.php

34 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * General utilities.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * This function allows to easily access a part from a php array.
10 * It is equivalent to want lodash get provides for JavaScript and is useful to have something similar
11 * in php so functions that do the same thing on the client and sever can have identical code.
12 *
13 * @param array $array An array from where we want to retrieve some information from.
14 * @param array $path An array containing the path we want to retrieve.
15 * @param array $default The return value if $array or $path is not expected input type.
16 *
17 * @return array An array matching the path specified.
18 */
19 function gutenberg_experimental_get( $array, $path, $default = array() ) {
20 // Confirm input values are expected type to avoid notice warnings.
21 if ( ! is_array( $array ) || ! is_array( $path ) ) {
22 return $default;
23 }
24
25 $path_length = count( $path );
26 for ( $i = 0; $i < $path_length; ++$i ) {
27 if ( ! isset( $array[ $path[ $i ] ] ) ) {
28 return $default;
29 }
30 $array = $array[ $path[ $i ] ];
31 }
32 return $array;
33 }
34