Autor Zpráva
4li
Profil
Hi!

Prosim skusenejsich o pomoc:

Array ( [user0] => andynoz [mode0] => 3 [login0] => 1230596070 [logoff0] => TIP [duration0] => TIP [rate0] => 10.00 USD [com0] => 50 [net_pay0] => 5.00 USD [user1] => andynoz [mode1] => 3 [login1] => 1230595026 [logoff1] => TIP [duration1] => TIP [rate1] => 50.00 USD [com1] => 50 [net_pay1] => 25.00 USD [user2] => andynoz [mode2] => 3 [login2] => 1230594930 [logoff2] => 1230596274 [duration2] => 22.40 [rate2] => 3.00 USD [com2] => 50 [net_pay2] => 33.60 USD [user3] => charliez [mode3] => 3 [login3] => 1230588055 [logoff3] => TIP [duration3] => TIP [rate3] => 50.00 USD [com3] => 50 [net_pay3] => 25.00 USD [user4] => charliez [mode4] => 3 [login4] => 1230587993 [logoff4] => 1230591428 [duration4] => 57.25 [rate4] => 3.00 USD [com4] => 50 [net_pay4] => 85.88 USD [user5] => binniab [mode5] => 3 [login5] => 1230572722 [logoff5] => TIP [duration5] => TIP [rate5] => 10.00 USD [com5] => 50 [net_pay5] => 5.00 USD [user6] => binniab [mode6] => 3 [login6] => 1230572717 [logoff6] => 1230573312 [duration6] => 9.92 [rate6] => 3.00 USD [com6] => 50 [net_pay6] => 14.88 USD [user7] => binniab [mode7] => 3 [login7] => 1230571985 [logoff7] => 1230572482 [duration7] => 8.28 [rate7] => 3.00 USD [com7] => 50 [net_pay7] => 12.42 USD [user8] => rennis [mode8] => 3 [login8] => 1230570188 [logoff8] => TIP [duration8] => TIP [rate8] => 50.00 USD [com8] => 50 [net_pay8] => 25.00 USD [user9] => rennis [mode9] => 3 [login9] => 1230570035 [logoff9] => 1230571878 [duration9] => 30.72 [rate9] => 3.00 USD [com9] => 50 [net_pay9] => 46.08 USD [user10] => venturis [mode10] => 3 [login10] => 1230551805 [logoff10] => 1230552747 [duration10] => 15.70 [rate10] => 3.00 USD [com10] => 50 [net_pay10] => 23.55 USD [user11] => venturis [mode11] => 3 [login11] => 1230549489 [logoff11] => TIP [duration11] => TIP [rate11] => 50.00 USD [com11] => 50 [net_pay11] => 25.00 USD [user12] => venturis [mode12] => 3 [login12] => 1230549434 [logoff12] => TIP [duration12] => TIP [rate12] => 50.00 USD [com12] => 50 [net_pay12] => 25.00 USD [user13] => venturis [mode13] => 3 [login13] => 1230548551 [logoff13] => 1230551141 [duration13] => 43.17 [rate13] => 3.00 USD [com13] => 50 [net_pay13] => 64.76 USD)

V tomto Array() je vypis jedneho, opakujuceho sa, riadku..
[user0] => andynoz [mode0] => 3 [login0] => 1230596070 [logoff0] => TIP [duration0] => TIP [rate0] => 10.00 USD [com0] => 50 [net_pay0] => 5.00 USD
..pri ktorom sa meni vzdy len ciselna hodnota pri keys.

Ako by ste sa dopracovali k cislu, ktore je vzdy posledne, tj. 13 (v hore v uvedenom poli), resp. akym sposobom by ste spocitali kolko jednotlivych [userX] pole obsahuje - a tym padom sa dostali k cislu 13?

Dik moc za kazdu radu!
DJ Miky
Profil
Pokud je počet těch položek (user, mode, login,...) pořád stejný, tak:
count($pole)/8
Pokud ho neznáš a pole je řazené vždy takto (položky s nejvyšším číslem na konci), tak můžeš třeba nějak takhle:
intval(preg_replace('[^0-9]+','',end(array_keys($pole))))
4li
Profil
DJ Miky
dik za radu, ale ani jedno nefunguje, pretoze ten uvedeny priklad je len cast povodneho Array(), ktory vyzera takto:

Array ( [group_ppm] => 1.00 USD [group_com] => 1 [group_com_tip] => 1 [private_ppm] => 3.00 USD [private_com] => 50 [private_com_tip] => 50 [pay_period_len] => 604800 [pay_period_begin] => 1231056000 [group_minutes] => 0.00 [group_minutes_pay] => 0.00 USD [private_minutes] => 187.43 [private_minutes_pay] => 281.16 USD [net_pay] => 281.16 USD [group_tips] => 0.00 USD [private_tips] => 135.00 USD [net_tips] => 135.00 USD [net_total] => 416.16 USD [user0] => andynoz [mode0] => 3 [login0] => 1230596070 [logoff0] => TIP [duration0] => TIP [rate0] => 10.00 USD [com0] => 50 [net_pay0] => 5.00 USD [user1] => andynoz [mode1] => 3 [login1] => 1230595026 [logoff1] => TIP [duration1] => TIP [rate1] => 50.00 USD [com1] => 50 [net_pay1] => 25.00 USD [user2] => andynoz [mode2] => 3 [login2] => 1230594930 [logoff2] => 1230596274 [duration2] => 22.40 [rate2] => 3.00 USD [com2] => 50 [net_pay2] => 33.60 USD [user3] => charliez [mode3] => 3 [login3] => 1230588055 [logoff3] => TIP [duration3] => TIP [rate3] => 50.00 USD [com3] => 50 [net_pay3] => 25.00 USD [user4] => charliez [mode4] => 3 [login4] => 1230587993 [logoff4] => 1230591428 [duration4] => 57.25 [rate4] => 3.00 USD [com4] => 50 [net_pay4] => 85.88 USD [user5] => binniab [mode5] => 3 [login5] => 1230572722 [logoff5] => TIP [duration5] => TIP [rate5] => 10.00 USD [com5] => 50 [net_pay5] => 5.00 USD [user6] => binniab [mode6] => 3 [login6] => 1230572717 [logoff6] => 1230573312 [duration6] => 9.92 [rate6] => 3.00 USD [com6] => 50 [net_pay6] => 14.88 USD [user7] => binniab [mode7] => 3 [login7] => 1230571985 [logoff7] => 1230572482 [duration7] => 8.28 [rate7] => 3.00 USD [com7] => 50 [net_pay7] => 12.42 USD [user8] => rennis [mode8] => 3 [login8] => 1230570188 [logoff8] => TIP [duration8] => TIP [rate8] => 50.00 USD [com8] => 50 [net_pay8] => 25.00 USD [user9] => rennis [mode9] => 3 [login9] => 1230570035 [logoff9] => 1230571878 [duration9] => 30.72 [rate9] => 3.00 USD [com9] => 50 [net_pay9] => 46.08 USD [user10] => venturis [mode10] => 3 [login10] => 1230551805 [logoff10] => 1230552747 [duration10] => 15.70 [rate10] => 3.00 USD [com10] => 50 [net_pay10] => 23.55 USD [user11] => venturis [mode11] => 3 [login11] => 1230549489 [logoff11] => TIP [duration11] => TIP [rate11] => 50.00 USD [com11] => 50 [net_pay11] => 25.00 USD [user12] => venturis [mode12] => 3 [login12] => 1230549434 [logoff12] => TIP [duration12] => TIP [rate12] => 50.00 USD [com12] => 50 [net_pay12] => 25.00 USD [user13] => venturis [mode13] => 3 [login13] => 1230548551 [logoff13] => 1230551141 [duration13] => 43.17 [rate13] => 3.00 USD [com13] => 50 [net_pay13] => 64.76 USD [total_login_time] => 228.58 )

Myslim, ze by sa dal pouzit tvoje 2. riesenie ak by sa trochu poupravilo.

Dik za pomoc!
bohyn
Profil
4li
A co treba pouzit dvojrozmerne pole?
4li
Profil
bohyn
Uvedeny priklad je vystup s ktorym ja nedokazem nic urobit. Mozem pracovat len s tym co vidis.

Nejaky napad?
Alphard
Profil
4li
nevím, jestli je tohle ideální způsob přenosu, napadá mě jen tohle

$pocet = -1;
foreach ($pole as $key => $hod)
if (ereg ("user", $key)) $pocet++;
echo $pocet;


ale budou zkontrolovány všechny klíče, efektivita je bude nebezpečně blížit nule, pomaleji to snad nejde...

jestli se můžete spolehnout na to, že největší hodnoty jsou na konci, použijte radši tohle

$pole = array_reverse ($pole);
foreach ($pole as $key => $hod)
{
  if (ereg ("user", $key)) break;
  $user = $key;
}
echo substr ($user, 4);
4li
Profil
Alphard
DELO!

Pouzil som 2. moznost. Ano je iste, ze najvacsie hodnoty su vzdy na konci a ten sposob co si pouzil ty ma nenapadol. Takze dik za radu, zase som o nieco chytrejsi ;)

Inak, viem, ze je to neprakticke, ale ten Array() je volany cez API call, takze s nim nedokazem nic ine urobit, len ho vyuzit taky, aky je..

Thx & Respect ;)

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: