>>> lst = ['dingo', 'wombat', 'wallaby'] >>> [w.title() for w in lst] ['Dingo', 'Wombat', 'Wallaby'] >>>
In python, there are easy todo methods with list comprehension.
And what about php with array('dingo', 'wombat', 'wallaby'); ?
Is there an understanding of the array or some kind of assembly function or, as a rule, a loop on it?
EDIT
function addCaps( Iterator $it ) { echo ucfirst( $it->current() ) . '<br />'; return true; } $array = array( 'dingo', 'wombat', 'wallaby' ); try { $it = new ArrayIterator( $array ); iterator_apply( $it, 'addCaps', array($it) ); } catch(Exception $e) { echo $e->getMessage(); }
Look at the code is not too simple, as I expected?
source share