Using PHP, let’s say I have this string:
$letters = "abcde";
I would like to add the character “7” between every character, but so it only occurs once. The result should be an array as follows:
$lettersArray = array(
7abcde,
a7bcde,
ab7cde,
abc7de,
abcd7e,
abcde7
);
Note: the length of $letters is dynamic from 1 to 12 characters
I have tried using loops with array_splice and str_split with implode, but I can’t quite figure out the right logic.
Try this:
What this does is take each element of the array, and inserts the letter 7 in an incrementing fashion into the array item.