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





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

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


Już sobie poradziłem, ale to dzięki vtunerowi, on mnie naprowadził (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Zmieniłem:

Kod
            if       ($ElmentArray[502] != 0) {
                $Missiles[502] += $ElmentArray[502];
            } elseif ($ElmentArray[503] != 0) {
                $Missiles[503] += $ElmentArray[503];
            }


na to:

Kod
            if       ($ElmentArray[0] == '502') {
                $Missiles[502] += $ElmentArray[1];
            } elseif ($ElmentArray[0] == '503') {
                $Missiles[503] += $ElmentArray[1];
            }


Ten post edytował Sebcioo 4.04.2008, 19:27:15
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 - 17:41