Skip to content

Instantly share code, notes, and snippets.

@gemblue
Last active September 11, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gemblue/046d51ce955423a13fa8b402c9b40e9e to your computer and use it in GitHub Desktop.
Save gemblue/046d51ce955423a13fa8b402c9b40e9e to your computer and use it in GitHub Desktop.
PHP Generator Function
<?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