arrays.php
3 days ago
dates.php
3 days ago
general.php
3 days ago
index.php
3 days ago
screen.php
3 days ago
strings.php
3 days ago
arrays.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /* |
| 8 | * Foo Functions - Arrays |
| 9 | * A bunch of common and useful functions related to arrays |
| 10 | * |
| 11 | * Author: Brad Vincent |
| 12 | * Author URI: http://fooplugins.com |
| 13 | * License: GPL2 |
| 14 | */ |
| 15 | |
| 16 | if ( !function_exists( 'foo_safe_get' ) ) { |
| 17 | /** |
| 18 | * safely get a value from an array |
| 19 | * |
| 20 | * @param array $array The array we want to extract info from. |
| 21 | * @param string $key The key of the item within the array. |
| 22 | * @param mixed $default The default value toi return if the value is not found in the array. |
| 23 | * |
| 24 | * @return mixed |
| 25 | */ |
| 26 | function foo_safe_get($array, $key, $default = null) { |
| 27 | if ( !is_array( $array ) ) return $default; |
| 28 | $value = array_key_exists( $key, $array ) ? $array[$key] : null; |
| 29 | if ( $value === null ) { |
| 30 | return $default; |
| 31 | } |
| 32 | |
| 33 | return $value; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if ( !function_exists( 'safe_get_from_request' ) ) { |
| 38 | |
| 39 | /** |
| 40 | * Safely get a value from the global $_REQUEST array |
| 41 | * |
| 42 | * @param string $key The key of the item within the array. |
| 43 | * @param mixed $default The default value toi return if the value is not found in the array. |
| 44 | * |
| 45 | * @return mixed |
| 46 | */ |
| 47 | function safe_get_from_request($key, $default = null) { |
| 48 | return foo_safe_get( $_REQUEST, $key, $default ); |
| 49 | } |
| 50 | } |
| 51 |