Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Sortowanie Array z xml
r4zick
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 8.05.2008

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


Witam mam plik xml z zawartością np:
Kod
<status>
    <oplayers>310</oplayers>
</status>

......

<sessions>
    <plr>
      <name>Mand</name>
      <race>1</race>
      <class>2</class>
      <gender>0</gender>
      <pvprank>0</pvprank>
      <level>70</level>
      <map>530</map>
      <areaid>3703</areaid>
      <xpos>-1792.188110</xpos>
      <ypos>5503.968750</ypos>
      <ontime>0 hours, 2 minutes, 51 seconds</ontime>
      <latency>57</latency>
    </plr>
    <plr>
      <name>Ultan</name>
      <race>3</race>
      <class>1</class>
      <gender>0</gender>
      <pvprank>0</pvprank>
      <level>18</level>
      <map>0</map>
      <areaid>87</areaid>
      <xpos>-9457.599609</xpos>
      <ypos>85.759277</ypos>
      <ontime>0 hours, 55 minutes, 37 seconds</ontime>
      <latency>48</latency>
    </plr>
    <plr>
      <name>Wujekfester</name>
      <race>8</race>
      <class>4</class>
      <gender>0</gender>
      <pvprank>0</pvprank>
      <level>70</level>
      <map>1</map>
      <areaid>1637</areaid>
      <xpos>1582.832031</xpos>
      <ypos>-4403.465332</ypos>
      <ontime>0 hours, 39 minutes, 51 seconds</ontime>
      <latency>88</latency>
    </plr>
</sessions>


Chciał bym go posortować za pomocą php według level od 70 do 1. Do pobrania danych z xml używam SimpleXML. Lecz nie wiem jak posortować, bo tworzy mi się array.

Ten post edytował r4zick 8.05.2008, 20:46:03
Go to the top of the page
+Quote Post
bim2
post
Post #2





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


usort" title="Zobacz w manualu PHP" target="_manual
  1. <?php
  2. function cmp($a, $b)
  3. {
  4. if ($a['latency'] == $b['latency']) {
  5. return 0;
  6. }
  7. return ($a['latency'] < $b['latency']) ? -: 1;
  8. }
  9.  
  10.  
  11. usort($a, "cmp");
  12.  
  13. foreach ($a as $key => $value) {
  14. echo "$key: $value\n";
  15. }
  16. ?>


Ten post edytował bim2 8.05.2008, 18:57:18


--------------------
Go to the top of the page
+Quote Post
r4zick
post
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 8.05.2008

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


@UP to nie działa.

Poradziłem sobie. Użyłem array_multisort.

Ten post edytował r4zick 8.05.2008, 20:45:49
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 18:18