1 | <?php |
||
18 | class ArrayUtilities |
||
19 | { |
||
20 | /** |
||
21 | * Search a two-dimensional array based on a specific key located in one of the inner arrays. |
||
22 | * |
||
23 | * In the following example array, this function could search each 'first_name' key in each of the inner arrays. |
||
24 | * |
||
25 | * ```php |
||
26 | * $records = array( |
||
27 | * array( |
||
28 | * 'id' => 2135, |
||
29 | * 'first_name' => 'John', |
||
30 | * 'last_name' => 'Doe', |
||
31 | * ), |
||
32 | * array( |
||
33 | * 'id' => 3245, |
||
34 | * 'first_name' => 'Sally', |
||
35 | * 'last_name' => 'Smith', |
||
36 | * ) |
||
37 | * ); |
||
38 | * ``` |
||
39 | * |
||
40 | * @param array $array The target two-dimensional array we will be searching |
||
41 | * @param string $column The name of the key that each inner array will have whose value will be checked |
||
42 | * @param string $search The value that will be searched for |
||
43 | * |
||
44 | * @since 0.1.0 |
||
45 | * |
||
46 | * @return mixed This function returns an int or string if the key is found. This function will return false if the |
||
47 | * key was not found; be sure to use "===" for comparison. |
||
48 | */ |
||
49 | 43 | public static function array_search_column ($array, $column, $search) |
|
68 | |||
69 | /** |
||
70 | * array_merge_recursive does indeed merge arrays, but it converts values with duplicate |
||
71 | * keys to arrays rather than overwriting the value in the first array with the duplicate |
||
72 | * value in the second array, as array_merge does. I.e., with array_merge_recursive, |
||
73 | * this happens (documented behavior): |
||
74 | * |
||
75 | * array_merge_recursive(array('key' => 'org value'), array('key' => 'new value')); |
||
76 | * => array('key' => array('org value', 'new value')); |
||
77 | * |
||
78 | * array_merge_recursive_distinct does not change the datatypes of the values in the arrays. |
||
79 | * Matching keys' values in the second array overwrite those in the first array, as is the |
||
80 | * case with array_merge, i.e.: |
||
81 | * |
||
82 | * array_merge_recursive_distinct(array('key' => 'org value'), array('key' => 'new value')); |
||
83 | * => array('key' => array('new value')); |
||
84 | * |
||
85 | * Parameters are passed by reference, though only for performance reasons. They're not |
||
86 | * altered by this function. |
||
87 | * |
||
88 | * @param array $array1 |
||
89 | * @param array $array2 |
||
90 | * |
||
91 | * @return array |
||
92 | * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk> |
||
93 | * @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com> |
||
94 | */ |
||
95 | public static function array_merge_recursive_distinct (array &$array1, array &$array2) |
||
113 | } |