yii2 arrayhelper::map vs array_map


Recently i was working on YII2 project in which i came across arrayhelper::map() and was thinking alternate in php.
so i used array_map() also tested the performance of both in yii2 by start time and end time for both ,surprising was that execution time remain same.please let me know if there is any alternate that will execute faster then arrayhelper::map().

Adding the code in yii2:

function find_field($value){ $value['id'] = $value['name']; return $value['id']; } $array = ['1'=>['id'=>1,'name' =>"pramodh",'address' =>'45 vk street','loc'=>'cbe'],'2'=>['id'=>2,'name' =>"pramodh kumar",'address' =>'45343 vk street','loc'=>'pune']]; $a = array_map(array($this,'find_field'),$array); print_r($a);

yii2 code:

$list = ArrayHelper::map($array, 'id''name');


Please leave your comments below for alternate solution.

Thank you for visiting.

Comments

Popular posts from this blog

create pdf by using javascript

yii framework simple shopping cart tutorial for beginners