Hallo,
ich will die X-ten Elemente eines Arrays anzeigen.
Hier mein bisheriger Code:
$anz=10; // Anzahl der anzuzeigenden Elemente je Seite
$pos=2; // aktuelle Seite
$xx=0; // Counter-Variable
// Ein Array mit n Elementen, Die Schlüssel sind alphanummerisch
$arr = array(
"Hallo_a" => "Hallo1",
"Hallo_b" => "Hallo2",
"Hallo_c" => "Hallo3",
"Hallo_d" => "Hallo4",
...
"Hallo_x" => "Hallo24",
"Hallo_y" => "Hallo25",
"Hallo_z" => "Hallo26"
);
// Und hier meine bisherige Idee:
// Das komplette Array durchlaufen, befindet sich der Schlüssel nicht // im gewünschten Bereich, Schleife ohne Ausdruck fortsetzen.
foreach ($arr as $k => $v){
$xx++;
if ($xx <= $Pos * $anz or $xx > ($pos + 1) * $anz) continue;
print $xx.". ".$k." ".$v."<br>\n";
};
Ich suche nun einen Ansatz, der mir die große Schleife erspart. So etwas wie View_Schlüssel ($arr, 20, 10); -> Zeige 10 Schlüssel ab Position 20.
Kann mir jemand helfen?
Gruß, Mario