| 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 |
* |
| 16 |
* @return array Containing a set of css rules. |
| 17 |
*/ |
| 18 |
function gutenberg_experimental_get( $array, $path ) { |
| 19 |
$path_length = count( $path ); |
| 20 |
for ( $i = 0; $i < $path_length; ++$i ) { |
| 21 |
if ( empty( $array[ $path[ $i ] ] ) ) { |
| 22 |
return null; |
| 23 |
} |
| 24 |
$array = $array[ $path[ $i ] ]; |
| 25 |
} |
| 26 |
return $array; |
| 27 |
} |
| 28 |
|