Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$string1 = "2-2-2000-2000-";
我怎样才能得到以下结果? For $output1 -> 2 For $output2 -> 2-2 For $output3 -> 2-2-2000 For $output4 -> 2-2-2000-2000
For $output1 -> 2 For $output2 -> 2-2 For $output3 -> 2-2-2000 For $output4 -> 2-2-2000-2000
这是做你想做的吗?
$array = explode('-', $string1); for ($i = 1; $i < count($array); $i++) { echo 'For $output' . $i . ' -> ' . implode('-', array_slice($array, 0, $i)) . "\n"; }