[SOLVED] string manipulation A-B…-X-Y to Y-A-B-…-X


I have a string in this format:

Each substring is seperated by ‘-‘


My question is how to move the last substring to the first as


in php

Thanks a lot.


Here’s some code that’ll do it:

// Split the string into an array
$letters = explode('-', 'A-B-C-X-Y');

// Pop off the last letter
$last_letter = array_pop($letters);

// Concatenate and rejoin the letters
$result = $last_letter . '-' . implode('-', $letters);

Answered By – Michael Louis Thaler

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *