| Conditions | 4 |
| Paths | 2 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 2 | public function uniqueMultiDim($key=null) |
|
| 19 | { |
||
| 20 | 2 | if (isset($key)){ |
|
| 21 | 1 | $tempArray = array(); |
|
| 22 | 1 | $keyArray = array(); |
|
| 23 | 1 | $i = 0; |
|
| 24 | |||
| 25 | 1 | foreach($this->array as $val) { |
|
|
|
|||
| 26 | 1 | if (!in_array($val[$key], $keyArray)) { |
|
| 27 | 1 | $keyArray[$i] = $val[$key]; |
|
| 28 | 1 | $tempArray[$i] = $val; |
|
| 29 | } |
||
| 30 | 1 | $i++; |
|
| 31 | } |
||
| 32 | |||
| 33 | 1 | $this->array = $tempArray; |
|
| 34 | }else{ |
||
| 35 | 1 | $this->array = array_values(array_map("unserialize", array_unique(array_map("serialize", $this->array)))); |
|
| 36 | } |
||
| 37 | 2 | return $this; |
|
| 38 | } |
||
| 39 | } |
||
| 40 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: