How to parse html table to array with symfony dom crawler

table = $crawler->filter('table')->filter('tr')->each(function ($tr, $i) {
    return $tr->filter('td')->each(function ($td, $i) {
        return trim($td->text());

The above example will give you a multidimensional array where the first layer are the table lines «tr» and the second layer are the table columns «td».

If you got nested tables, this code will flatten them out nicely into a single dimension array.

$html = 'MY HTML HERE';
$crawler = new Crawler($html);
$flat = function(string $selector) use ($crawler) {
    $result = [];
    $crawler->filter($selector)->each(function ($table, $i) use (&$result) {
        $table->filter('tr')->each(function ($tr, $i) use (&$result) {
            $tr->filter('td')->each(function ($td, $i) use (&$result) {
                $html = trim($td->html());
                if (strpos($html, '<table') !== FALSE) return;
                $iterator = $td->getIterator()->getArrayCopy()[0];
                $address = $iterator->getNodePath();
                if (!empty($html)) $result[$address] = $html;
    return $result;
// The selector gotta point to the most outwards table.
print_r($flat('#Prod fieldset div table'));