26
loading...
This website collects cookies to deliver better user experience
<?php
function produceBells(int $num)
{
$bells = [];
for ($i = 0; $i < $num; $i++) {
$bells[] = '🔔';
}
return $bells;
}
$hundredBells = produceBells(100); // 8.3KB
foreach ($hundredBells as $bell) {
echo $bell . ' ';
}
function generateBells(int $num)
{
for ($i = 0; $i < $num; $i++) {
yield '🔔';
}
}
$hundredBells = generateBells(100); //544 bytes
foreach ($hundredBells as $bell) {
echo $bell . ' ';
}
Is that a hundred bells? I sure hope so, I get lost when counting them!
Snippet | Type | Memory usage |
---|---|---|
1 | Array | 8280 bytes |
2 | Generator | 544 bytes |