1: <?php
2: /**
3: * ManiaLib - Lightweight PHP framework for Manialinks
4: *
5: * @see http://code.google.com/p/manialib/
6: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
7: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
8: * @version $Revision: 590 $:
9: * @author $Author: maximeraoust $:
10: * @date $Date: 2011-12-27 19:40:38 +0100 (mar., 27 déc. 2011) $:
11: */
12:
13: namespace ManiaLib\Utils;
14:
15: abstract class Arrays
16: {
17:
18: /**
19: * Returns the specified array element if it exists, or the default value
20: */
21: static function get($array, $key, $default = null)
22: {
23: return array_key_exists($key, $array) ? $array[$key] : $default;
24: }
25:
26: /**
27: * Returns the specified element if it exists and is not null (==), or the
28: * default value
29: */
30: static function getNotNull($array, $key, $default = null)
31: {
32: if(array_key_exists($key, $array) && $array[$key])
33: {
34: return $array[$key];
35: }
36: return $default;
37: }
38:
39: static function getProperty(array $array, $property, $default = null)
40: {
41: $values = array();
42: foreach($array as $key => $value)
43: {
44: if(is_null($value->$property))
45: {
46: $values[$key] = $default;
47: }
48: else
49: {
50: $values[$key] = $value->$property;
51: }
52: }
53: return $values;
54: }
55:
56: }
57:
58: ?>