Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][mysql]Problem z explode
Sebcioo
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 14.10.2007
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


Witam, mam problem z funkcją explode. Dany mam poniższy kod:

Kod
        $BuildQueue    = $b_hangar_id;
        $BuildArray    = explode (";", $BuildQueue);
        for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
            $ElmentArray = explode (",", $BuildArray[$QElement] );
            if       ($ElmentArray[502] != 0) {
                $Missiles[502] += $ElmentArray[502];
            } elseif ($ElmentArray[503] != 0) {
                $Missiles[503] += $ElmentArray[503];
            }
        }


Gdzie "$b_hangar_id" = "502,6;502,5"
Missiles[502] i Missiles[503] = 3

Chodzi głównie o to, żeby dane z $b_hangar_id były dodawane to Missiles. Czyli np. jeśli w b_hangar_id znajdują się 2 wartości "502,5;502,7" to liczba po przecinku to ilość jaką trzeba dodać. Czyli łącznie 12 (7+5). Niestety $ElementArray wyrzuca mi pusty wynik i nie wiem co jest źle.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
vtuner
post
Post #2





Grupa: Zarejestrowani
Postów: 220
Pomógł: 10
Dołączył: 23.08.2005
Skąd: Łódź

Ostrzeżenie: (0%)
-----


Spróbuj tak:

  1. <?php
  2. $BuildQueue = $b_hangar_id;
  3. $BuildArray = explode (";", $BuildQueue);
  4. for ($QElement = 0; $QElement < count($BuildArray); $QElement++) 
  5. {
  6. $ElmentArray[$QElement] = explode (",", $BuildArray[$QElement] );
  7. $Missiles[$ElmentArray[$QElement][0]] += $ElmentArray[$QElement][1];
  8. }
  9. ?>


Ten post edytował vtuner 4.04.2008, 18:44:16
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: 7.10.2025 - 08:40