-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arr.php
45 lines (39 loc) · 860 Bytes
/
Arr.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
42
43
44
45
<?php
namespace Modulus\Support;
use Modulus\Support\DEPConfig;
class Arr
{
/**
* Get value that's like ?
*
* @param array $array
* @param mixed $value
* @return void
*/
public static function like(array $array, $value)
{
foreach($array as $row => $line) {
if (str_contains($line, $value)) return $line;
}
}
/**
* Replace array key
*
* @param array $array
* @param mixed $oldKey
* @param mixed $newKey
* @return array $newArray
*/
public static function replace_key(array $array, $oldKey, $newKey) : array
{
$newArray = array();
foreach ($array as $key => $value) {
if ($key == $oldKey) {
$newArray = array_merge($newArray, [$newKey => $value]);
} else {
$newArray = array_merge($newArray, [$key => $value]);
}
}
return $newArray;
}
}