$goal ) { $here = $here - $move; if (array_search($here, $used_array) !== FALSE) { $count = -1; break; } } else { $here = $here + $move; } $used_array[] = $i; // 既に使用した } echo $count."\n";