Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sabbirdev's avatar

PHP replace in Array

I am beginner to laravel. I am trying to access array input from my API request.

For postman, I have array as key called file_name_list and its value like ["m_profile.png","aa_image.jpg","new_pan.jpg"]. I want to access that array in my controller. That values should go into 3 seperate variables like

$profile = m_profile.png 

$aadhar = aa_image.jpg

$pan = new_pan.jpg

For that I am trying to use replace and explode functions in controller.

$filenamelist1 =  Str::replaceArray(array(' ','"', '[',']'),[""], $request->file_name_list);
$filename_str = explode(",",$filenamelist1);

After this I want to store values from explode array to 3 variables as mentioned above using for loop

But I am facing problems like in Str::replaceArray 2 parameter should be array and for explode 2 parameter should be string.

How should I use replace and explode to get required result? please guide. Thanks in advance.

0 likes
2 replies
Nakov's avatar

@sabbirdev use list() and json_decode to turn your string into array:

list($var1, $var2, $var3) = json_decode(
    '["m_profile.png","aa_image.jpg","new_pan.jpg"]',
    true
);
1 like

Please or to participate in this conversation.