-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
utils.php
27 lines (26 loc) · 796 Bytes
/
utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
* General utilities.
*
* @package gutenberg
*/
/**
* This function allows to easily access a part from a php array.
* It is equivalent to want lodash get provides for JavaScript and is useful to have something similar
* in php so functions that do the same thing on the client and sever can have identical code.
*
* @param array $array An array from where we want to retrieve some information from.
* @param array $path An array containing the path we want to retrieve.
*
* @return array Containing a set of css rules.
*/
function gutenberg_experimental_get( $array, $path ) {
$path_length = count( $path );
for ( $i = 0; $i < $path_length; ++$i ) {
if ( empty( $array[ $path[ $i ] ] ) ) {
return null;
}
$array = $array[ $path[ $i ] ];
}
return $array;
}