reverse string php

前端 未结 4 2078
面向向阳花
面向向阳花 2021-01-06 16:06

What would be the best way to reverse the order of a string so for instance,

\'Hello everybody in stackoverflow\'

becomes

\         


        
4条回答
  •  盖世英雄少女心
    2021-01-06 16:40

    In prose that is:

    • First turn the string into an array of words
    $words = explode(' ', $string);
    
    • Second, inverse the order of the elements in that array
    $reversed_string = implode(' ', array_reverse($words));
    

    Reading the whole list of string and array functions in PHP is VERY helpful and will save tons of time.

提交回复
热议问题