Last active
September 11, 2016 14:09
-
-
Save gemblue/046d51ce955423a13fa8b402c9b40e9e to your computer and use it in GitHub Desktop.
PHP Generator Function
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 | |
// Get number | |
function get_one_two_three() { | |
for ($i = 1; $i <= 3; $i++) { | |
yield $i; | |
} | |
} | |
$result = get_one_two_three(); | |
foreach ($result as $value) { | |
echo "$value\n"; | |
} | |
// Helper | |
function convert($size) | |
{ | |
$unit=array('b','kb','mb','gb','tb','pb'); | |
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; | |
} | |
echo 'Memory terpakai : ' . convert(memory_get_usage(true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment