Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] przeszukiwanie tablicy
Wolfie
post 19.08.2009, 18:38:33
Post #1





Grupa: Zarejestrowani
Postów: 686
Pomógł: 0
Dołączył: 10.11.2008
Skąd: Łódź

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


Witam


W efekcie pobierania z bazy danych otrzymalem taka tablice :

Oto czesc :

Cytat
Array ( [0] => Array ( [0] => Array ( [token] => Microsoft [spamcount] => 5 [hamcount] => 1 ) )
[1] => Array ( [0] => Array ( [token] => MSDOS [spamcount] => 12 [hamcount] => 3 ) )
[2] => Array ( [0] => Array ( [token] => and [spamcount] => 24 [hamcount] => 6 ) )
[3] => Array ( [0] => Array ( [token] => Windows [spamcount] => 20 [hamcount] => 5 ) )
[4] => Array ( [0] => Array ( [token] => use [spamcount] => 16 [hamcount] => 4 ) ))


No i teraz chce sie dostac do poszczegolnych elementow tablicy, no i zastosowalem do tego nastepujaca konstrukcje :

  1. function calculateProbability() {
  2. $probValues = $this->getTokensValues();
  3. //print_r($probValues);
  4. foreach($probValues as $key=>$val) {
  5. //print_r($val).'<br />';
  6. foreach($val as $val1) {
  7. //print_r($val1);
  8. foreach($val1 as $key1=>$val2) {
  9. echo '$tab['.$key.'] - '.$key1.' - '.$val2.'<br />';
  10. }
  11. }
  12. }
  13. }


W efekcie czego dostaje cos takiego :

Cytat
$tab[0] - token - Microsoft
$tab[0] - spamcount - 5
$tab[0] - hamcount - 1
$tab[1] - token - MSDOS
$tab[1] - spamcount - 12
$tab[1] - hamcount - 3
$tab[2] - token - and
$tab[2] - spamcount - 24
$tab[2] - hamcount - 6
$tab[3] - token - Windows
$tab[3] - spamcount - 20
$tab[3] - hamcount - 5
$tab[4] - token - use
$tab[4] - spamcount - 16
$tab[4] - hamcount - 4


No i teraz pytanie:
Czy nie ma mozliwosci jakos latwiej dostac sie do tych elementow niz poprzez 3 petle foreach ? exclamation.gif
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 13:15