3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = array( 'background1.png - abc1.png','background1.png - abc2.png', 'background1.png - abc3.png','background2.png - abc4.png', 'background2.png - abc5.png','background2.png - abc6.png'); foreach ($arr as $elem) { $temp = explode('-', $elem); $key = trim($temp[0]); $fruits[$key][] = trim($temp[1]); } echo '<pre>';print_r($fruits);echo '</pre>';
Output for 4.3.0 - 7.2.0
<pre>Array ( [background1.png] => Array ( [0] => abc1.png [1] => abc2.png [2] => abc3.png ) [background2.png] => Array ( [0] => abc4.png [1] => abc5.png [2] => abc6.png ) ) </pre>