<?php $str = "Part1:Part2:Part3:Part4"; $parts = explode(':', $str); $result = []; for ($i = 0; $i < count($parts); $i++) { $i % 2 === 0 ? $k = $parts[$i] : $result[$k] = $parts[$i]; } print_r($result);
You have javascript disabled. You will not be able to edit any code.