@@ -15,6 +15,7 @@ Loading this Helper
15
15
This helper is loaded using the following code:
16
16
17
17
.. literalinclude :: array_helper/001.php
18
+ :lines: 2-
18
19
19
20
Available Functions
20
21
===================
@@ -29,24 +30,28 @@ The following functions are available:
29
30
:rtype: mixed
30
31
31
32
This method allows you to use dot-notation to search through an array for a specific-key,
32
- and allows the use of a the '*' wildcard. Given the following array:
33
+ and allows the use of a the `` * `` wildcard. Given the following array:
33
34
34
35
.. literalinclude :: array_helper/002.php
36
+ :lines: 2-
35
37
36
- We can locate the value of ' fizz' by using the search string " foo.buzz.fizz" . Likewise, the value
37
- of baz can be found with " foo.bar.baz" :
38
+ We can locate the value of `` fizz `` by using the search string `` foo.buzz.fizz `` . Likewise, the value
39
+ of `` baz `` can be found with `` foo.bar.baz `` :
38
40
39
41
.. literalinclude :: array_helper/003.php
42
+ :lines: 2-
40
43
41
- You can use the asterisk as a wildcard to replace any of the segments. When found, it will search through all
44
+ You can use the asterisk (`` * ``) as a wildcard to replace any of the segments. When found, it will search through all
42
45
of the child nodes until it finds it. This is handy if you don't know the values, or if your values
43
46
have a numeric index:
44
47
45
48
.. literalinclude :: array_helper/004.php
49
+ :lines: 2-
46
50
47
- If the array key contains a dot, then the key can be escaped with a backslash:
51
+ If the array key contains a dot (`` . ``) , then the key can be escaped with a backslash (`` \ ``) :
48
52
49
53
.. literalinclude :: array_helper/005.php
54
+ :lines: 2-
50
55
51
56
.. note :: Prior to v4.2.0, ``dot_array_search('foo.bar.baz', ['foo' => ['bar' => 23]])`` returned ``23``
52
57
due to a bug. v4.2.0 and later returns ``null ``.
@@ -73,21 +78,24 @@ The following functions are available:
73
78
from, e.g., the ``find() `` function of a model:
74
79
75
80
.. literalinclude :: array_helper/006.php
81
+ :lines: 2-
76
82
77
83
Now sort this array by two keys. Note that the method supports the dot-notation
78
84
to access values in deeper array levels, but does not support wildcards:
79
85
80
86
.. literalinclude :: array_helper/007.php
87
+ :lines: 2-
81
88
82
- The ``$players `` array is now sorted by the ' order' value in each players'
83
- ' team' subarray. If this value is equal for several players, these players
84
- will be ordered by their ' position' . The resulting array is:
89
+ The ``$players `` array is now sorted by the `` order `` value in each players'
90
+ `` team `` subarray. If this value is equal for several players, these players
91
+ will be ordered by their `` position `` . The resulting array is:
85
92
86
93
.. literalinclude :: array_helper/008.php
94
+ :lines: 2-
87
95
88
96
In the same way, the method can also handle an array of objects. In the example
89
- above it is further possible that each ' player' is represented by an array,
90
- while the ' teams' are objects. The method will detect the type of elements in
97
+ above it is further possible that each `` player `` is represented by an array,
98
+ while the `` teams `` are objects. The method will detect the type of elements in
91
99
each nesting level and handle it accordingly.
92
100
93
101
.. php :function :: array_flatten_with_dots(iterable $array[, string $id = '']): array
@@ -101,16 +109,19 @@ The following functions are available:
101
109
as separators for the keys.
102
110
103
111
.. literalinclude :: array_helper/009.php
112
+ :lines: 2-
104
113
105
114
On inspection, ``$flattened `` is equal to:
106
115
107
116
.. literalinclude :: array_helper/010.php
117
+ :lines: 2-
108
118
109
119
Users may use the ``$id `` parameter on their own, but are not required to do so.
110
120
The function uses this parameter internally to track the flattened keys. If users
111
121
will be supplying an initial ``$id ``, it will be prepended to all keys.
112
122
113
123
.. literalinclude :: array_helper/011.php
124
+ :lines: 2-
114
125
115
126
.. php :function :: array_group_by(array $array, array $indexes[, bool $includeEmpty = false]): array
116
127
@@ -126,12 +137,15 @@ The following functions are available:
126
137
The example shows some data (i.e. loaded from an API) with nested arrays.
127
138
128
139
.. literalinclude :: array_helper/012.php
129
-
130
- We want to group them first by "gender", then by "hr.department" (max depth = 2).
140
+ :lines: 2-
141
+
142
+ We want to group them first by ``gender ``, then by ``hr.department `` (max depth = 2).
131
143
First the result when excluding empty values:
132
144
133
145
.. literalinclude :: array_helper/013.php
134
-
146
+ :lines: 2-
147
+
135
148
And here the same code, but this time we want to include empty values:
136
149
137
150
.. literalinclude :: array_helper/014.php
151
+ :lines: 2-
0 commit comments