<?php $arr = [ 'This is option: one', 'This is option: two', 'This is option: 😜' ]; $target = [ 'This is option:' => [ 'one', 'two', '😜' ] ]; function convertArr(array $src): array { $prevString = null; $newArray = []; foreach ($src as $string) { if ($prevString) { // stuck here } $prevString = $string; } return $newArray; } assert(convertArr($arr) === $target);
You have javascript disabled. You will not be able to edit any code.