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
nevt
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


  1. <?php
  2. $BuildArray = explode (';', $b_hangar_id);
  3. foreach($BuildArray as $ElmentArray)
  4. {
  5. $Element = explode (',', $ElmentArray );
  6. $Missiles[(int)$Element[0]] += (int)$Element[1];
  7. }
  8. ?>


Ten post edytował nevt 4.04.2008, 19:06:54
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 - 20:58