tbCombineArray.php
Gesponsorde koppelingen
PHP script bestanden
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
Class tbCombineArray {
public function __construct () {
}
/**
* combineArray
* combines 2 arrays
*
* @param aArray1 first array for combining
* @param aArray2 second array for combining
*
* @acces public
*
* @return array
**/
function combineArray($aArray1, $aArray2) {
if(!is_array($aArray1) || !is_array($aArray2)) {
return NULL;
}
$aNewArray = Array();
foreach($aArray1 as $siIndex => $mValue){
if(isset($aArray2[$siIndex]) && is_array($mValue) && is_array($aArray2[$siIndex])) {
$aNewArray[$siIndex] = $this->combineArray($mValue, $aArray2[$siIndex]);
} else {
$aNewArray[$siIndex] = $aArray1[$siIndex];
}
}
foreach($aArray2 as $siIndex => $mValue){
if(!isset($aArray1[$siIndex])) {
$aNewArray[$siIndex] = $aArray2[$siIndex];
}
}
return $aNewArray;
}
}
?>
Class tbCombineArray {
public function __construct () {
}
/**
* combineArray
* combines 2 arrays
*
* @param aArray1 first array for combining
* @param aArray2 second array for combining
*
* @acces public
*
* @return array
**/
function combineArray($aArray1, $aArray2) {
if(!is_array($aArray1) || !is_array($aArray2)) {
return NULL;
}
$aNewArray = Array();
foreach($aArray1 as $siIndex => $mValue){
if(isset($aArray2[$siIndex]) && is_array($mValue) && is_array($aArray2[$siIndex])) {
$aNewArray[$siIndex] = $this->combineArray($mValue, $aArray2[$siIndex]);
} else {
$aNewArray[$siIndex] = $aArray1[$siIndex];
}
}
foreach($aArray2 as $siIndex => $mValue){
if(!isset($aArray1[$siIndex])) {
$aNewArray[$siIndex] = $aArray2[$siIndex];
}
}
return $aNewArray;
}
}
?>