27
Before I am censured by the question, notice beforehand that the purpose of it is simply to level curiosity. I know that the foreach
is the most suitable means for this.
But I would like to know the following:
What are the ways to iterate with a array
in PHP, without using foreach
, so that you can access índice
and the valor
(as in the foreach
)?
I would like to see examples with for
, while
or even functions.
I’ll leave a array
for response model:
$array = array(
'stack' => 'Overflow',
'linguagem' => 'Português',
'tags' => array('PHP', 'Iteração', 'Array')
);
I need the interaction to happen this way (exemplifying with foreach
):
foreach($array as $indice => $valor)
{
var_dump($indice, $valor);
}
Heed: The only case not accepted for iteration with for
is that of $i++
, since it is a plastered way and only serves to array
numerically indexed.
It would be interesting each one who answered exemplify with only one form :)
– Wallace Maxters
xD need to answer this question!
– rray
I didn’t quite understand how the exit should be, it should print
tags
and then0
,PHP
... or0
,PHP
?. 'Cause I’m running out therein– rray
Excellent question, it is very cool to see that the community is very creative to give N solutions
– SneepS NinjA