There are two functions called:
$array_keys = array_keys($array); // retorna só as chaves
$array_values = array_values($array); // retorna só os valores
Example:
$array = array('194800' => 'Forest', '194811' => 'River', '194812' => 'Sky');
$array_keys = array_keys($array);
$array_values = array_values($array);
print_r($array_keys);
print_r($array_values);
You can also join key + value:
$array = array_combine($keys, $values);
In the loop:
// para mostrar os valores. por padrão já vai retornar só os valores,
// mas você pode aplicar a função array_values($array) se quiser.
foreach ($array as $result) {
echo $result;
echo "<br>";
}
// para mostrar as chaves
foreach (array_keys($array) as $result) {
echo $result;
echo "<br>";
}
And to show key and value in the loop:
foreach ($array as $key => $value) {
echo "Key: $key; Value: $value<br />\n";
}
Ok, and how do I use it in the loop? type $code = array_keys($array) and for the value $value = array_values($array);
– Adrianoecris
@Adrianoecris, I gave an update on the reply.
– Paulo Costa
@Adrianoecris, http://php.net/manual/en/control-structures.foreach.php
– Paulo Costa
The link above has several cool examples, take a look :)
– Paulo Costa