Completed
Push — master ( 424d4e...c1a616 )
by Jean-Christophe
03:24
created

JArray::implode()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 11
nc 3
nop 2
1
<?php
2
3
namespace Ajax\service;
4
5
class JArray {
6
7
	public static function isAssociative($array) {
8
		return (array_keys($array)!==range(0, count($array)-1));
9
	}
10
11
	public static function getValue($array, $key, $pos) {
12
		if (array_key_exists($key, $array)) {
13
			return $array [$key];
14
		}
15
		$values=array_values($array);
16
		if ($pos<sizeof($values))
17
			return $values [$pos];
18
	}
19
20
	public static function getDefaultValue($array, $key, $default) {
21
		if (array_key_exists($key, $array)) {
22
			return $array [$key];
23
		} else
24
			return $default;
25
	}
26
27
	public static function implode($glue,$pieces){
28
		$result="";
29
		if(\is_array($glue)){
30
			$size=\sizeof($pieces);
31
			if($size>0){
32
				for($i=0;$i<$size-1;$i++){
33
					$result.=$pieces[$i].@$glue[$i];
34
				}
35
				$result.=$pieces[$size-1];
36
			}
37
		}else{
38
			$result=\implode($glue, $pieces);
39
		}
40
		return $result;
41
	}
42
}