array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'recursivearrayiterator.haschildren.php', 1 => 'RecursiveArrayIterator::hasChildren', ), 'up' => array ( 0 => 'class.recursivearrayiterator.php', 1 => 'RecursiveArrayIterator', ), 'prev' => array ( 0 => 'recursivearrayiterator.getchildren.php', 1 => 'RecursiveArrayIterator::getChildren', ), 'next' => array ( 0 => 'class.recursivecachingiterator.php', 1 => 'RecursiveCachingIterator', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/spl/recursivearrayiterator/haschildren.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
RecursiveArrayIterator::hasChildren — 現在のエントリが配列あるいはオブジェクトであるかどうかを返す
現在のエントリが配列あるいはオブジェクトであるかどうか、つまり RecursiveArrayIterator::getChildren() でイテレータを取得できるかどうかを返します。
この関数にはパラメータはありません。
例1 RecursiveArrayIterator::hasChildren() の例
<?php
$fruits = array("a" => "lemon", "b" => "orange", array("a" => "apple", "p" => "pear"));
$iterator = new RecursiveArrayIterator($fruits);
while ($iterator->valid()) {
// 子を持つかどうかを調べます
if ($iterator->hasChildren()) {
// すべての子を表示します
foreach ($iterator->getChildren() as $key => $value) {
echo $key . ' : ' . $value . "\n";
}
} else {
echo "No children.\n";
}
$iterator->next();
}
?>
上の例の出力は以下となります。
No children. No children. a : apple p : pear