<?php
$start = microtime(true);
$a = [
'hallo welt',
' asss ',
'adasd13e1 123w1 23w123w21',
'1232',
'1231245rt235491340921830',
'41904e09218i3219ß21093ß02193ß0219ß0',
'2135r423',
'!2242321',
'21421421',
'44',
'1',
'12435r2390ß4038i12ß2190ßi2ß10',
];
$a = array_filter($a, function($value) {
return strlen($value) <= 10;
});
$b = 5;
$s = 10;
$a = array_slice($a, 0, $b);
$a = array_combine( range($s, $b*$s , $s), $a);
var_dump( $a, microtime(true)-$start );
$start = microtime(true);
$a = [
'hatlo welt',
' asss ',
'adasd13e1 123w1 23w123w21',
'1232',
'1231245rt235491340921830',
'41904e09218i3219ß21093ß02193ß0219ß0',
'2135r423',
'!2242321',
'21421421',
'44',
'1',
'12435r2390ß4038i12ß2190ßi2ß10',
];
$i = 0;
$result =[];
foreach ($a as $bullet_point) {
if (strlen($bullet_point) > 10 ) {
continue;
}
$i+=1;
$sort = $i * $s;
$result[$sort] = $bullet_point;
if ($i == $b) {
break;
}
}
if ($i < 0) {
return false;
}
var_dump($result, microtime(true)-$start );
preferences:
35.18 ms | 402 KiB | 5 Q