Created
December 8, 2016 07:06
-
-
Save ManishLSN/1849c2970a9789e9c4da98a8a6c20d8f to your computer and use it in GitHub Desktop.
this is just a testing gist
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
<pre> | |
<?php | |
$origarray1 = array(2.4, 2.6, 3.5); | |
$origarray2 = array(2.4, 2.6, 3.5); | |
print_r(array_map('floor', $origarray1)); // $origarray1 stays the same | |
// changes $origarray2 | |
array_walk($origarray2, function (&$v, $k) { $v = floor($v); }); | |
print_r($origarray2); | |
// this is a more proper use of array_walk | |
array_walk($origarray1, function ($v, $k) { echo "$k => $v", "\n"; }); | |
// array_map accepts several arrays | |
print_r( | |
array_map(function ($a, $b) { return $a * $b; }, $origarray1, $origarray2) | |
); | |
// select only elements that are > 2.5 | |
print_r( | |
array_filter($origarray1, function ($a) { return $a > 2.5; }) | |
); | |
?> | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment