I want to add +2 to an array elements without looping(foreach).
$arr=array(5,6,8,0,55,64,1);
wanted output:
$arr=array(7,8,10,2,57,66,3)
Then array_map is you friend :
function foo($n) { return($n + 2); }
$arr = array(5,6,8,0,55,64,1);
$ouput = array_map("foo", $arr);
EDIT after the answer of Gautam3164 : array_walk is also an option, indeed. Just dont forget that array_map returns a new array when array_walk takes a reference and updates your array.
foreach($a as $arr) {$arr[$a] += 2; }from AQ