Tag: Gets the value class name a static method. com www map ddd
Array Helper Class Arrayhelper1. What is the array helper class
The Yii Array helper class provides additional static methods that allow you to work with arrays more efficiently.
A, Get value (GetValue)
class user{ public$name = ' Alex ';}
$array = [ ' foo ' = = [ new User (), DDD ]]
Get the value of name
PHP Method:
$value isset ($array$arraynull;
arrayhelper Method:
$value = Arrayhelper::getvalue ($array, ' foo.bar.name ');
2. Get column (GetColumn)
Gets the value of a column from a multidimensional array or an array of objects
$data = [[/// key equals the property name of the object, value equals the object's property values [' id ' = ' 456 ', ' data ' = ' def '],
]
Arrayhelper Method:
$ids = Arrayhelper::getcolumn ($data, ' id ');
Results: [' 123 ', ' 456 '];
3. Build a mapping table (map)
You can use the map method to extract data from a multidimensional array or an array of objects, create a mapping table (a key-value array),
Specifies the key name and value of the pre-built mapping table in the parameter list of the map method.
$array = [' id ' = ' 123 ', ' name ' = ' aaa ', ' email ' = ' x '],[' id ' = ' 456 ', ' name ' = > ' BBB ', ' email ' = ' y ',[' id ' = ' = ' 789 ', ' name ' = ' CCC ', ' email ' = ' ' Z '], '// Arrayhelper Method: $result = Arrayhelper::map ($array, ' id ', ' name '); /* result: [' 123 ' = ' aaa ' ' 456 ' + ' bbb ' 789 ' + ' CCC,] */
Note: This article for the author (44106-kangaroo) after reading Wei teach you to learn Yii2.0 video after the note, if reproduced please indicate the source: http://www.cnblogs.com/chrdai/p/8006752.html
Yii2 Array Helper Class Arrayhelper