- memory_get_usage: documentation ( source)
- range: documentation ( source)
<?php
$array = [];
$startMemory = memory_get_usage();
foreach (range(1, 100000) as $i) {
$array[] = "adfsdfghsfghfsgh $i";
}
$seq = memory_get_usage() - $startMemory;
echo "seq array: $seq bytes\n";
foreach (range(1, 100000) as $i) {
$array["test$i"] = "sdfghsfghsfg $i";
}
$seqassoc = memory_get_usage() - $startMemory;
echo "seq+assoc array: $seqassoc bytes\n";
echo "multiplier: " . $seqassoc / $seq;