Splitting strings in PHP and get last part

前端 未结 13 2338
无人及你
无人及你 2020-12-08 04:39

I need to split a string in PHP by \"-\" and get the last part.

So from this:

abc-123-xyz-789

I expect to get

13条回答
  •  猫巷女王i
    2020-12-08 05:02

    As has been mentioned by others, if you don't assign the result of explode() to a variable, you get the message:

    E_STRICT: Strict standards: Only variables should be passed by reference

    The correct way is:

    $words = explode('-', 'hello-world-123');
    $id = array_pop($words); // 123
    $slug = implode('-', $words); // hello-world
    

提交回复
热议问题