Reputation: 3215
I have an array, and I want to get the first value into a foreach loop. then send that value to a function.
This does not work
foreach ($frequency as $i) {
showphp_AlexVortaro (getphp_AlexVortaro ($frequency[$i]));
showphp_Smartfm(getphp_Smartfm($frequency[$i]));
}
Upvotes: 4
Views: 1495
Reputation: 32878
The current();
function would return the first value;
echo current($array);
Upvotes: 0
Reputation: 342635
I think you mean to use the current 'exposed' offset as your functions' arguments:
foreach($frequency as $i) {
showphp_AlexVortaro (getphp_AlexVortaro($i));
showphp_Smartfm(getphp_Smartfm($i));
}
or:
for($i=0; $i<count($frequencies); $i++) {
showphp_AlexVortaro(getphp_AlexVortaro($frequencies[$i]));
showphp_Smartfm($frequencies[$i]);
}
Upvotes: 2
Reputation: 2897
$i is the value of your array in the foreach loop. Instead of sending $frequency[$i] you must use '$i'.
If you want to fetch the keys use the following construction:
foreach ($array as $key => $value)
{
// Do something
}
Upvotes: 2