Just started coding PHP, could someone point me to the right direction? I've got:
$text = Barcelona, Catalunya, Spain
I want to get only the first and last word which should be
OUTPUT: Barcelona, Spain
I tried this, but it gives me the 2 last words:
$text = explode(",", $text);
$size = array_slice($text, -2, 2);
$text = implode(",", $size);
OUTPUT: Catalunya, Spain
Could someone help please?
array_popandarray_shift. They return first and last elements from a given array.$text[0] for first and end($text) for last elementorreset($text) for first element