<?php
declare(strict_types=1);

// Pure matchers: never accept an ID found in an unrelated nested object.
function cat8f_row($rows, int $id, string $name): ?array
{
    if (!is_array($rows)) return null;
    foreach ($rows as $row) {
        if (is_array($row) && isset($row['id'], $row['name'])
            && (string)$row['id'] === (string)$id && (string)$row['name'] === $name) {
            return $row;
        }
    }
    return null;
}

function cat8f_tree($nodes, int $id, string $name): bool
{
    if (!is_array($nodes)) return false;
    foreach ($nodes as $node) {
        if (!is_array($node)) continue;
        if (isset($node['id'], $node['name'])
            && (string)$node['id'] === (string)$id && (string)$node['name'] === $name) {
            return true;
        }
        if (isset($node['children']) && cat8f_tree($node['children'], $id, $name)) {
            return true;
        }
    }
    return false;
}
