-1

I am unable to get as to why I am unable to change the value of an array of an array. Here's the code I tried

print_r($target_file);
foreach ($target_file as $k => $v) {
   unset ($v['tmp_name']);
   print_r($v);
   $v['tmp_name'] = "joker";
   print_r($v);
}

print_r($target_file);

And output I get is:

(
    [0] => Array
        (
            [name] => order-confirmation-60dc3f6f8d7f3.pdf
            [type] => application/pdf
            [tmp_name] => C:\Users\kbged\Desktop\XAMPP\tmp\php2FDB.tmp
            [error] => 0
            [size] => 367185
        )

)
Array
(
    [name] => order-confirmation-60dc3f6f8d7f3.pdf
    [type] => application/pdf
    [error] => 0
    [size] => 367185
)
Array
(
    [name] => order-confirmation-60dc3f6f8d7f3.pdf
    [type] => application/pdf
    [error] => 0
    [size] => 367185
    [tmp_name] => joker
)
Array
(
    [0] => Array
        (
            [name] => order-confirmation-60dc3f6f8d7f3.pdf
            [type] => application/pdf
            [tmp_name] => C:\Users\kbged\Desktop\XAMPP\tmp\php2FDB.tmp
            [error] => 0
            [size] => 367185
        )

)

Any ideas as to why I am unable to update the array value outside the scope of this for loop?

Thanks!

0

1 Answer 1

2

You have to change the value of the array variable itself

print_r($target_file);
foreach ($target_file as $k => $v) {
   $target_file[$k]['tmp_name'] = "joker";
}
print_r($target_file);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.