Created
October 10, 2013 18:45
-
-
Save prodeveloper/6923382 to your computer and use it in GitHub Desktop.
Snapshot showing use of array_map and foreach in a project that capitalizes strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Loops array using array walk/ map | |
*/ | |
class LoopMap extends Loops { | |
function __construct($array) { | |
$this -> array = $array; | |
} | |
function capitalize_names(){ | |
return array_map(array($this,'_capitalize_name'),$this->array); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Loops test array using the conventional for loop | |
*/ | |
class LoopFor extends Loops { | |
function __construct($array) { | |
$this -> array = $array; | |
} | |
function capitalize_names(){ | |
foreach ($this->array as &$name) { | |
$name=$this->_capitalize_name($name); | |
} | |
return $this->array; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment