helpers.php ➔ array_alias_key()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 7
eloc 8
c 2
b 0
f 2
nc 4
nop 2
dl 0
loc 19
rs 8.2222
1
<?php
2
3
if( ! function_exists('array_alias_key'))
4
{
5
	/**
6
	 * Replace the array keys with aliases
7
	 *
8
	 * @param  array  $input
9
	 * @param  array  $alias
10
	 * @return array
11
	 */
12
	function array_alias_key(Array $input, Array $alias)
13
	{
14
		$combined = array();
15
16
		foreach($input as $key => $value)
17
		{
18
			if(is_array($value) and is_array($alias[$key]) and isset($alias[$key]['name']))
19
			{
20
				$combined[$alias[$key]['name']] = array_alias_key($value, $alias[$key]['aliases']);
21
22
			}
23
			elseif(isset($alias[$key]) and $value !== null)
24
			{
25
				$combined[$alias[$key]] = $value;
26
			}
27
		}
28
29
		return $combined;
30
	}
31
}