I have a question, let's say I have this array:
$array = ["one", "two", "three", "four"];
And I want to add "test"
between elements in the array, so it becomes like this:
$array = ["test", "one", "test", "two", "test", "three", "test", "four"];
My current way of doing it is by doing this:
$array = ["one", "two", "three", "four"];
$newArray = "test." . implode("test.", $array);
$newArray = explode(".", $newArray);
But I want a way that's cleaner, can somebody help me please?
$newArray
is a string not an array.$newArray = explode(".", $newArray);
, I edited the post.foreach()
loop is about the simplest.foreach()
way, as it's also better just in case one of the elements had a dot in them.