我在 php 中有一個巨大的數(shù)組(~800 個子數(shù)組):$arrayx = array([0] => array("side1" => "XTSWS", "side2" => "WRXXC", "value" => "150"),[1] => array("side1" => "WRXXC", "side2" => "TXXBD", "value" => "110"),[2] => array("side1" => "XTSWS", "side2" => "GVFDS", "value" => "40"),[3] => array("side1" => "XTSWS", "side2" => "ABNMDA", "value" => "1350"),[4] => array("side1" => "TTTSY", "side2" => "WRXXC", "value" => "1150"),[5] => array("side1" => "WDWDD", "side2" => "KGADSD", "value" => "10050"),[6] => array("side1" => "ZZSJH", "side2" => "PPPEIJD", "value" => "1750"),... 800);對于雙方,我試圖找到從一個值到另一個值的所有可能路徑,例如:XTSWS -> WRXXCXTSWS -> TXXBD -> WRXXCXTSWS -> TXXBD -> ZZSJH -> WRXXC在 PHP 中有什么有效的方法可以做到這一點(diǎn)嗎?我在 Python 等中找到了一些使用圖形/節(jié)點(diǎn)的示例。$values = $this->findAllPaths("XTSWS", "WRXXC");function findAllPaths($from, $to){}
PHP - 查找數(shù)組中的所有路徑(2 邊)
12345678_0001
2023-04-02 10:41:46