Dizi Döngü - Bir foreach döngü içine ilk değeri almak

3 Cevap

Ben bir dizi var, ve ben bir foreach döngü içine ilk değerini almak istiyorum. daha sonra bir fonksiyona bu değeri gönderebilirsiniz.

  • Bu işe yaramazsa

    foreach ($frequency as $i) {        
       showphp_AlexVortaro (getphp_AlexVortaro ($frequency[$i]));
       showphp_Smartfm(getphp_Smartfm($frequency[$i]));        
    }
    

3 Cevap

I think Eğer fonksiyonlarının argüman olarak offset 'maruz' geçerli kullanmak demek:

foreach($frequency as $i) {        
   showphp_AlexVortaro (getphp_AlexVortaro($i));
   showphp_Smartfm(getphp_Smartfm($i));        
}

veya:

for($i=0; $i<count($frequencies); $i++) {        
   showphp_AlexVortaro(getphp_AlexVortaro($frequencies[$i]));
   showphp_Smartfm($frequencies[$i]);        
}

$ I foreach döngü içinde dizinin değerdir. $ Yerine frekans gönderme [$ i] Eğer '$ i' kullanmanız gerekir.

Eğer almak isterseniz tuşları aşağıdaki yapı kullanın:

foreach ($array as $key => $value) 
{
 // Do something
}

current(); function ilk değerini dönecekti;

echo current($array);