I have an array:
array(3) {
[0]=> string(1) "3"
[1]=> string(3) "488"
[2]=> string(3) "177"
}
I want to have a foreach
for its values, which returns the number in the array.
How can I do that?
I have an array:
array(3) {
[0]=> string(1) "3"
[1]=> string(3) "488"
[2]=> string(3) "177"
}
I want to have a foreach
for its values, which returns the number in the array.
How can I do that?
Here is the PHP doc
http://php.net/manual/en/control-structures.foreach.php
The code would look like
foreach ($array as $value) {
echo "Value: $value<br />\n";
}
By numbers do you mean the strings?
var_dump(array_values($your_array));
foreach ( $array as $value ) {
echo $value;
}
You can find more about foreach here.
I sure hope I understood your question..
foreach ($yourArray as $value)
{
// ...
}
// OR
foreach ($yourArray as $key => $value)
{
// ...
}
You can extract values and keys with array_values() and array_keys().