I am trying to modify an associative array eg.
array(
'key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3'
)
to something like
array(
':key1' => 'val1xx',
':key2' => 'val2xx',
':key3' => 'val3xx'
// ^ colen
)
You may recognize I am trying to convert it into something I can use in PDOStatement::execute(). I dont currently need to modify the value, in this case. But will like to know just for knowledge
What can I use to do that? I am thinking foreach can do most things, but do functions like array_map or array_walk provide any benefits? Like performance? Or just looks different
There exists a big performance gap between the foreach and the array_map method. The fastest is the foreach construct. This construct can be five to six times as fast as an anonymous function, at least when there is not much to do within the loop. In most scenarios, the time it takes to iterate over the array is negligible compared to the time spend in the loop or anonymous function. So this performance difference does not really matter.For more information see link here.