Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Jak zrobić numerację po kolei rekordów?
woxala123
post
Post #1





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


  1. echo "<P>Total number of combinations:" . count($solutions) . "</p>";
  2. echo "<p> solutions: </p>";
  3. foreach ($solutions as $sol) {
  4. echo "<p> {$sol[0]} {$sol[1]} {$sol[2]} {$sol[3]} {$sol[4]}</p>";

Powyżej kawałek kodu który wyświetla kombinację liczb tylko chcę jeszcze wyswietlić po kolei nr tych rekordów
Dla przykładu
id liczby
1. 1 2 3
2. 3 4 6
3. itp
4. itp
Myślałem jakąś pętlą for tylko nie potrafię tego zgrać z wynikami.
Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
woxala123
post
Post #2





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


  1. $numbers = array(
  2. 9 ,21,44,2,32,1,39,31
  3. );
  4.  
  5. $solutions = array();
  6.  
  7. function generate($k, $solution)
  8. {
  9. global $solutions, $numbers;
  10. if (count($solution) == 5) {
  11. $solutions[] = $solution;
  12. }
  13. if (count($solution) < 5 )
  14. for ($i = $k; $i < count($numbers); $i++) {
  15. $solution[] = $numbers[$i];
  16. generate($i + 1, $solution);
  17. array_pop($solution);
  18. }
  19.  
  20. }
  21.  
  22. generate(0, array());
  23.  
  24.  
  25. echo "<P>Total number of combinations:" . count($solutions) . "</p>";
  26. echo "<p> solutions: </p>";
  27. sort($numbers);
  28. foreach ($numbers as $key => $val) {
  29.  
  30. foreach ($solutions as $sol) {
  31. echo "<p> {$sol[0]} {$sol[1]} {$sol[2]} {$sol[3]} {$sol[4]}</p>";
  32. echo "numbers[" . $key . "] = " . $val . "\n";
  33.  
  34.  
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 13:36