3v4l.org

run code in 300+ PHP versions simultaneously
<?php function inject_hyphens($word, $positions) { $pad = 0; foreach ($positions as $position) { $word = substr($word, 0, $position + $pad + 1) . '-' . substr($word, $position + $pad + 1, strlen($word)); $pad++; } return $word; } $input = array('syl-labification', 'sylla-bification', 'syllabi-fication', 'syllabifi-cation', 'syllabifica-tion', 'syllabification' ); //wanted $output = 'syl-la-bi-fi-ca-tion'; $positions = array(); foreach($input as $word) { preg_match_all('/-/', $word, $matches, PREG_OFFSET_CAPTURE); foreach($matches[0] as $key => $value) { $positions[] = $value[1]; } } $positions = array_unique($positions); var_dump(inject_hyphens('syllabification', $positions));
Output for git.master, git.master_jit, rfc.property-hooks
string(20) "syll-ab-if-ic-at-ion"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
58.46 ms | 401 KiB | 8 Q