0

I have one parameter every time it comes from the request object in a standard order,I want to store that string into an array by splitting \for that i am using explode function it's throwing an error,please help me to explode with backslash

$obj = "App\Http\Data\User";
$array = explode("\",$obj);
3
  • 2
    You need "\\" to encode a backslash in a string.` So, $array = explode("\\",$obj); Commented Apr 5, 2022 at 15:28
  • A single \ is an escape character. so $array = explode("\\",$obj); Commented Apr 5, 2022 at 15:31
  • or use single quotes Commented Apr 5, 2022 at 16:12

1 Answer 1

1

You can use this:

$obj = "App\Http\Data\User";
$array = explode("\\",$obj);


print_r($array);

example here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.