RecursiveArrayIterator::hasChildren
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
RecursiveArrayIterator::hasChildren — Retorna se a entrada atual é um array ou um objeto
Descrição
public function RecursiveArrayIterator::hasChildren():
bool
Parâmetros
Esta função não possui parâmetros.
Valor Retornado
Retorna true se a entrada atual é um array ou um object,
caso contrário, false é retornado.
Exemplos
Exemplo #1 Exemplo de RecursiveArrayIterator::hasChildren()
<?php
$fruits = array("a" => "limão", "b" => "laranja", array("a" => "maçã", "p" => "pêra"));
$iterator = new RecursiveArrayIterator($fruits);
while ($iterator->valid()) {
// Verifica se há filhos
if ($iterator->hasChildren()) {
// imprime todos os filhos
foreach ($iterator->getChildren() as $key => $value) {
echo $key . ' : ' . $value . "\n";
}
} else {
echo "Sem filhos.\n";
}
$iterator->next();
}
?>
O exemplo acima produzirá:
Sem filhos.
Sem filhos.
a : maçã
p : pêra