<p>I'd like to get all the permutations of swapped characters pairs of a string. For example:</p>
<p>Base string: <code>abcd</code></p>
<p>Combinations:</p>
<ol>
<li><code>bacd</code></li>
<li><code>acbd</code></li>
<li><code>abdc</code></li>
</ol>
<p>etc.</p>
<h3>Edit</h3>
<p>I want to swap only letters that are next to each other. Like first with second, second with third, but not third with sixth.</p>
<p>What's the best way to do this?</p>
<h3>Edit</h3>
<p>Just for fun: there are three or four solutions, could somebody post a speed test of those so we could compare which is fastest?</p>
<h3>Speed test</h3>
<p>I made speed test of nickf's code and mine, and results are that mine is beating the nickf's at four letters (0.08 and 0.06 for 10K times) but nickf's is beating it at 10 letters (nick's 0.24 and mine 0.37)</p>

Edit: Markdown hates me today...
```
```
$input = "abcd";
$len = strlen($input);
$output = array();

for ($i = 0; $i < $len - 1; ++$i) {
    $output[] = substr($input, 0, $i)
              . substr($input, $i + 1, 1)
              . substr($input, $i, 1)
              . substr($input, $i + 2);
}
print_r($output);
```
```