Jump to content

Variable to array


dk4210

Recommended Posts

Hello Guys.

 

I have a question here..

 

I have a photo upload script that uploads photos to the server and then sends the photo name to another page via POST.

 

I only have one var name called $image_all

 

when I echo it this is what I get (When uploading 2 files)

This is the list 2011-12-05_0751.png,2011-12-05_0747.png

 

I also tested with "explode"

 print_r(explode(',', $image_all, 10));

 

and I get this

 

Array ( [0] => 2011-12-05_0751.png [1] => 2011-12-05_0747.png [2] => 

 

What I would like for it to do is assign an incremental var name to each image uploaded and passed in the POST.

 

Like this

 

$image1 =  2011-xx.png

$image2 = 2011-xx.png

$image3 = 2011-xx.png

 

It should created the variable names dynamically based on the number of images (Up to 10)

 

Thanks for your help!

 

 

 

Link to comment
Share on other sites

And what is not clear? :)

 

Take for() loop and set variables. I think it's better to use an array but not a set of variables:

 

<?php

$images=array();

for( $i=1; $i<=10; $i++) // may be not 10 but a number of loaded images

  $images[]=sprintf( '2011-%02d', $i );

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.