In terms of performance, which is the better option?
While in object:
Case #1
public function test( $array ) {
return array_map( array( $this, 'do_something_to_element' ), $array );
}
Case #2
public function test( $array ) {
$return = array();
foreach ( $array as $value ) {
$return[] = do_something_to_element( $value );
}
return $return;
}
There are other uses of course and many many examples can be populated. I've seen comments that while in an object, array_map is slower than foreach loops.
In general is the array_map/array_walk functions faster to execute than the foreach loops in similar needs?
forloop, too?forloops tend to outperformforeach, and seeing as loops are constructs, and not function calls, I'd expect them to outperformarray_map