-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Manipulation.php
More file actions
52 lines (44 loc) · 1.23 KB
/
Array_Manipulation.php
File metadata and controls
52 lines (44 loc) · 1.23 KB
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
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Created by PhpStorm.
* User: denisolvr
*/
class Array_Manipulation
{
var $main_array;
/**
* @return mixed
*/
public function getMainArray()
{
return $this->main_array;
}
/**
* @param mixed $main_array
*/
public function setMainArray($main_array)
{
$this->main_array = $main_array;
}
public function __construct($array) {
return $this->setMainArray($array);
}
function groupArray(array $keys) {
// create the output array
$data_output = $this->main_array;
// assist var to index
$flag = 0;
//walk each element in array
foreach ($data_output as $array_each){
/*
* First at all transform the $keys in an array key/value after catch the array between
* the difference of $array each and $key with this difference We'll have that apply one more
* time the diff to extract the correctly intersection of the array
*/
$data_output[$flag] = array_diff_key($array_each,array_diff_key($array_each,array_flip($keys)));
//variable assist for index creation
$flag++;
}
return $data_output;
}
}