UnixDevel Posted February 10, 2012 Report Posted February 10, 2012 Array ( [Entertainment] => 0.558299 [Science] => 6.0291E-6 [Sports] => 0.441695 )am urmatorul array ,cum fac sa extrag primul element cel cu Entertainment ,atentie stiu ca se face cu $a['Entertainment'] ,chestia este ca acel array este dinamic ,cum as putea sa il fac sa fie static ....adika mie din array-ul respectiv trebuie sa extrag intodeauna doar primele 2 intrari Entertainment si Science...dar care pot fi diferite in alte cazuri Quote
BogdanNBV Posted February 10, 2012 Report Posted February 10, 2012 <?php$a = array('asdassda'=>2, 'caca'=>3, 'mue'=>33);$x = 1;foreach($a as $cheie=>$valoare){ if($x <=2) { echo $cheie."=>".$valoare."<br/>"; } $x++;}?>nu cred ca este cea mai buna metoda, sau cea mai rapida, dar functioneaza Quote
UnixDevel Posted February 10, 2012 Author Report Posted February 10, 2012 daps , am facut altfel merci oricum , Quote
BogdanNBV Posted February 10, 2012 Report Posted February 10, 2012 daca ai gasit alta modalitate, te rog, arata-mi, sa nu mor prost xD Quote
qbert Posted February 10, 2012 Report Posted February 10, 2012 (edited) Ai putea sa faci si astfel <?$a = array('asdas'=>'34','dfsd3'=>'23');$b = array_keys($a);print $a[$b[0]];?> Edited June 23, 2012 by qbert Quote