foreach ($sp_ind->series as $series) { foreach ($series->specimen as $specimen) { $taxon = $specimen->taxon; $taxon = trim($taxon); if (!isset($spec["{$taxon}"])) { $spec[] = $taxon; } else { } } } ksort($spec); //------------------------------------------------------- //------------------------------------------------------- $file = $xmldir . $tree . '.xml'; $xml = simplexml_load_file('kgbase/base/bases/' . $base . '/' . $index['taxonomy']); $all_taxonomy = convert_taxonomy($xml); $ranks = $all_taxonomy['ranks']; $taxons = $all_taxonomy['taxons']; //---print taxons //count taxons print 'Всего таксонов (по рангам):<br>'; foreach ($ranks as $lev => $rank) { $tax_count = count($taxons[$rank['taxon']]); $ranks[$lev]['count'] = 1; print '- ' . $rank['pseudonym'] . ': ' . $tax_count . '.<br>'; } //root $rtaxon = array_shift($taxons[$ranks[0]['taxon']]); print_taxon($rtaxon, $ranks[0]['taxon']); $rname = $rtaxon['name']; show_sub_taxa($taxons, $ranks, $rname, 1, $spec, $site, $base);
function construct_taxonomy($coll_search_result, $all_tax) { //arguments: numeric array of exists taxons (list), array: array1(ranks) array2 (taxons in order of ranks) $sel_taxons = array(); $all_taxonomy = convert_taxonomy($all_tax); foreach ($coll_search_result as $sp => $data) { $taxon = $data['taxon']; $taxon = trim($taxon); if (array_search($taxon, $sel_taxons) == false) { $sel_taxons[] = $taxon; } else { } } sort($sel_taxons); $ranks = $all_taxonomy['ranks']; $taxons = $all_taxonomy['taxons']; $n_ranks = count($ranks); $sel_struct = array(); //make array rank=>name of exists taxons for ($ir = 0; $ir < $n_ranks; $ir++) { $r_name = $ranks[$ir]['taxon']; foreach ($taxons["{$r_name}"] as $name => $content) { if (array_search($name, $sel_taxons) !== false) { $sel_struct["{$name}"] = $r_name; } else { } } } //make "final" array $end_items = array(); for ($ir = $n_ranks - 1; $ir >= 0; $ir--) { $r_name = $ranks[$ir]['taxon']; foreach ($taxons["{$r_name}"] as $name => $content) { if (isset($sel_struct["{$name}"])) { if (!isset($end_items["{$r_name}"])) { $end_items["{$r_name}"] = array(); } $end_items["{$r_name}"]["{$name}"] = $taxons["{$r_name}"]["{$name}"]; $item_parent = $end_items["{$r_name}"]["{$name}"]['parent']; $parent_lev = $ir - 1; while (isset($ranks[$parent_lev])) { $par_r_name = $ranks[$parent_lev]['taxon']; if (!isset($end_items["{$par_r_name}"])) { $end_items["{$par_r_name}"] = array(); } $parent_name = $end_items["{$par_r_name}"]["{$item_parent}"] = $taxons["{$par_r_name}"]["{$item_parent}"]; $item_parent = $end_items["{$par_r_name}"]["{$item_parent}"]['parent']; $parent_lev--; } } else { } } } //make new array of taxons - really exists in query $ranks_new = array(); for ($ir = 0; $ir < $n_ranks; $ir++) { $r_name = $ranks[$ir]['taxon']; if (isset($end_items["{$r_name}"])) { $ranks_new[$ir] = $ranks[$ir]; } } foreach ($end_items as $level => $taxon_level) { ksort($taxon_level); $end_items["{$level}"] = $taxon_level; } $end_items = array_reverse($end_items); $end_data = array(); $end_data['ranks'] = $ranks_new; $end_data['taxons'] = $end_items; $end_data['sel_taxons'] = $sel_taxons; return $end_data; return $end_data; }