use yii\helpers\ArrayHelper; $arr = [1, 2, 3, 4]; $newArr = ArrayHelper::map($arr, function ($val) { return $val * 2; }); // Output: [2, 4, 6, 8]
use yii\helpers\ArrayHelper; $users = [ ['id' => 1, 'name' => 'John', 'age' => 25], ['id' => 2, 'name' => 'Jane', 'age' => 30] ]; $idNameList = ArrayHelper::map($users, 'id', 'name'); // Output: [1 => 'John', 2 => 'Jane']In the above example, we extract the 'id' and 'name' values from an array of user objects and create a new array with the 'id' values as the keys and 'name' values as the values. The ArrayHelper map function is part of the yii\helpers package library in the Yii framework.