Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c55268a5
Commit
c55268a5
authored
Dec 02, 2014
by
Nikola Basic
Committed by
Carsten Brandt
Dec 02, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix typos in ArrayHelper guide [skip ci]
close #6349
parent
0633cb09
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
helper-array.md
docs/guide/helper-array.md
+11
-11
No files found.
docs/guide/helper-array.md
View file @
c55268a5
...
...
@@ -35,8 +35,8 @@ $value = ArrayHelper::getValue($array, 'foo.bar.name');
First method argument is where we're getting value from. Second argument specifies how to get the data. It could be one
of the following:
-
Name of array key or object property to retieve value from.
-
Set of dot separated array key or object property names. The one we've used in the example above.
-
Name of array key or object property to ret
r
ieve value from.
-
Set of dot separated array key
s
or object property names. The one we've used in the example above.
-
A callback returning a value.
The callback should be the following:
...
...
@@ -85,7 +85,7 @@ if (!ArrayHelper::keyExists('username', $data1, false) || !ArrayHelper::keyExist
## Retrieving Columns <a name="retrieving-columns"></a>
Often you need to get a column of values from array of data rows or objects. Common
keys
is getting a list of IDs.
Often you need to get a column of values from array of data rows or objects. Common
example
is getting a list of IDs.
```
php
$data
=
[
...
...
@@ -109,7 +109,7 @@ $result = ArrayHelper::getColumn($array, function ($element) {
## Re-indexing Arrays <a name="reindexing-arrays"></a>
In order to index
es an array according to a specified key
`index`
method could
be used. The input array should be
In order to index
an array according to a specified key, the
`index`
method can
be used. The input array should be
multidimensional or an array of objects. The key can be a key name of the sub-array, a property name of object, or
an anonymous function which returns the key value given an array element.
...
...
@@ -171,7 +171,7 @@ $result = ArrayHelper::map($array, 'id', 'name', 'class');
## Multidimensional Sorting <a name="multidimensional-sorting"></a>
`sort`
method helps to sort an array of objects or nested arrays by one or several keys. For example,
`
multi
sort`
method helps to sort an array of objects or nested arrays by one or several keys. For example,
```
php
$data
=
[
...
...
@@ -192,7 +192,7 @@ After sorting we'll get the following in `$data`:
];
```
Second argument that specifies keys to sort by c
ould
be a string if it's a single key, an array in case of multiple keys
Second argument that specifies keys to sort by c
an
be a string if it's a single key, an array in case of multiple keys
or an anonymous function like the following one:
```
php
...
...
@@ -211,7 +211,7 @@ PHP [sort()](http://php.net/manual/en/function.sort.php).
## Detecting Array Types <a name="detecting-array-types"></a>
It is handy to know whether array is indexed or an associative. Here's an example:
It is handy to know whether a
n a
rray is indexed or an associative. Here's an example:
```
php
// no keys specified
...
...
@@ -233,7 +233,7 @@ $encoded = ArrayHelper::htmlEncode($data);
$decoded
=
ArrayHelper
::
htmlDecode
(
$data
);
```
Only values will be encoded by default. By passing second argument as
`false`
you can encode arrays keys as well.
Only values will be encoded by default. By passing second argument as
`false`
you can encode array
'
s keys as well.
Encoding will use application charset and could be changed via third argument.
...
...
@@ -257,7 +257,7 @@ Encoding will use application charset and could be changed via third argument.
## Converting Objects to Arrays <a name="converting-objects-to-arrays"></a>
Often you need to convert an object or an array of objects into array. The most common case is converting active record
Often you need to convert an object or an array of objects into a
n a
rray. The most common case is converting active record
models in order to serve data arrays via REST API or use it otherwise. The following code could be used to do it:
```
php
...
...
@@ -282,8 +282,8 @@ The second argument is conversion mapping per class. We're setting a mapping for
Each mapping array contains a set of mappings. Each mapping could be:
-
A field name to include as is.
-
A key-value pair of desired array key name and model colum name to take value from.
-
A key-value pair of desired array key name and a callback which return
value will be used
.
-
A key-value pair of desired array key name and model colum
n
name to take value from.
-
A key-value pair of desired array key name and a callback which return
s value
.
The result of conversion above will be:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment