I have an array “$abc” which has 9 elements, as:-
Array
(
[a] => Jack
[b] => went
[c] => up
[d] => the
[e] => hill
[f] => but
[g] => never
[h] => came
[i] => back
)
Now I need to concat only the 4 elements starting from the “b” index to the “e” index only. But I don’t know what to do. I used the “implode()” function of PHP in cases where all the array elements are concatenated.
Any help is greatly appreciated.
You need to extract the desired values first and then use
implode. You could usearray_slice:That would produce
went up the hill.If you need to work with the literal keys, you need to be a bit more creative. In your case it would probably best just to loop through the array and compare, but you can do something exotic also: