1

How do you add an value with an => $key into an array, for example:

$images = array();

array_push($images, $_FILES['file']['tmp_name'] => $_FILES['file']['name']);

So the array would be like:

array('temporary_file_name' => 'file_name.zip');

But my IDE says it's invalid and would not work.

2 Answers 2

8

I think this is what you want:

$images[$_FILES['file']['tmp_name']] = $_FILES['file']['name'];
Sign up to request clarification or add additional context in comments.

Comments

0

See : [removed by Mod's]http://stackoverflow.com/questions/5017747/need-a-function-array-push-with-keys[/removed by Mod's] and you could build a nice and dynamic multi-array function with that solution, I'm sure.

Edit: ... well ... go ahead with this then ...:

   $some_array[count($some_array)]=$any_value;
   /* we added a new element with the last number as key */
   $all_keys=array_keys($some_array);
   $all_values = array_values($some_array);
   $all_keys[(count($some_array)-1)]=$a_key;
   $some_array=array_combine($all_keys, $all_values);

1 Comment

You don't need to insert line breaks. Additionally, please see the formatting help within the editor.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.