função atual PHP ()
PHP completa matriz de referência
Exemplos
valores de elementos de matriz Corrente de saída:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
?>
Correndo instância »
Definição e Uso
função atual () retorna o valor do elemento atual na matriz.
Cada matriz tem um ponteiro interno para o elemento "atual", o ponto inicial para inserir em primeiro elemento da matriz.
Dica: Esta função não irá mover o ponteiro interno.
métodos relacionados:
- End () - o ponteiro interno para o último elemento na matriz, e de saída.
- Next () - o ponteiro interno para o próximo elemento na matriz, e de saída.
- PREV () - o ponteiro interno para o último elemento da matriz, e de saída.
- RESET () - o ponteiro interno para o primeiro elemento na matriz, e de saída.
- a each () - Retorna nomes e valores de chave do elemento atual, e o ponteiro interno avança.
gramática
current( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
detalhes técnicos
retorna: | Ele retorna o valor do elemento atual na matriz, se o elemento atual é um elemento vazio não tem nenhum valor ou os retornos atuais falsas. |
---|---|
versão do PHP: | 4+ |
mais exemplos
exemplo 1
Todos os métodos de apresentação relevantes:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
Correndo instância »
PHP completa matriz de referência