3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* function balancedTagCloud(array $values, array $priorities): array { $low = min($priorities) - 1; $high = max($priorities) - $low; return array_map( fn($v, $p) => sprintf( '<h%1$d>%2$s</h%1$d>', ceil(($p - $low) / $high * 6), $v ), $values, $priorities ); } */ $artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"]; /*$counts = [ 'original' => [5, 3, 9, 1, 1, 3], 'no_ones' => [5, 3, 9, 7, 7, 3], 'skewed' => [5, 3, 9, 7, 111, 3], 'all_same' => [5, 5, 5, 5, 5, 5], 'only_two' => [9, 20, 9, 20, 9, 20], ]; foreach ($counts as $count) { echo implode("\n", balancedTagCloud($artist, $count)); echo "\n---\n"; }*/ $count = [5, 3, 9, 1, 1, 3]; $steps = 6; $tags = []; $min = 1e9; $max = -1e9; foreach ($artist as $i => $name) { $c = log($count[$i]); $min = min($min, $c); $max = max($max, $c); $tags[] = (object) ['weight' => $count[$i], 'name' => $name, 'count' => $c]; } $range = max(.01, $max - $min) * 1.0001; foreach ($tags as $obj) { $obj->weight = 1 + floor($steps * ($obj->count - $min) / $range); } foreach ($tags as $tag) { echo "<h$tag->weight>$tag->name</h$tag->weight>\n"; }
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
<h5>the roots</h5> <h3>michael jackson</h3> <h6>billy idol</h6> <h1>more</h1> <h1>and more</h1> <h3>and_YET_MORE</h3>
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
135.84 ms | 407 KiB | 5 Q