basicly I've got an array and want to call the same function for each element. Which way is it faster?
foreach($elemeents as $element){
callFunction($element);
}
OR
function callFunction($leements){
foreach($elements as $element){
//do something
}
}
thanx in advance, im just a beginner
Probably slightly faster with the loop inside the function, as there is a (slight) cost to each function call. However, it won't make much difference.
This is really premature optimization, and the root of all evil.
You should write it so it is clear, then if it's too slow, figure out where it's slow and optimize that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With