Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6583931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:28:23+00:00 2026-05-25T16:28:23+00:00

I have always sucked at complex arrays there must be something in my brain

  • 0

I have always sucked at complex arrays there must be something in my brain preventing me from ever understanding them. I will try to make this example really simple so we will not go off topic. I use this code to use numbers to represent each file name:

$mod_nums = array('1' => $input_zip_path . '01_mod_1.0.2.zip',

                  '2' => $input_zip_path . '02_mod_1.0.1.zip',
);

So when I use $mod_nums[’01’] it will display the path to that file. I have an array from the script that put these $mod_nums values into an array like so:

$files_to_zip = array(
    $mod_nums['1'],
    $mod_nums['2']
);

That worked fine. Now I wanted to add a $_POST value so that I can enter numbers like 1,2 and other numbers that I add to the $mod_nums array later like 1,3,6,12 for example. So I used an explode for those posted values:

$explode_mods  = explode(",", trim($_POST['mods']));

Now for the big question that is racking my brain and spent hours on and cannot get it to work…. I need for $files_to_zip to still be in an array and display the posted values of $mod_nums. So it would be like:

$files_to_zip = array( HAVE $_POSTED VALUES IN HERE );

I hope that makes sense. I need $files_to_zip to remain in array format, grab the file path to the zip files from the $mod_nums array, and display it all correctly so it would dynamically output:

$files_to_zip = array(’01_mod_1.0.2.zip’, ’02_mod_1.0.1.zip’);

so posted numbers will appear in an array format for the $files_to_zip variable. Make sense? In short I need an array to have dynamic values. Thanks 🙂

EDIT

Phew I figured it out myself from memory when I worked on something similar many years ago. This looks tough but it isn’t. I had to use a foreach and assign the variable into an array like so:

$blah = array();

foreach ($explode_mods as $value)
{
    $blah[] = $mod_nums[$value];
}

then I just assigned $files_to_zip to $blah:

$files_to_zip = $blah;

works perfectly 🙂 I just forgot how to dynamically assign values into an array.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:28:24+00:00Added an answer on May 25, 2026 at 4:28 pm
    // filenames array
    $mod_nums = array('1' => $input_zip_path . '01_mod_1.0.2.zip',
                      '2' => $input_zip_path . '02_mod_1.0.1.zip',
    );
    
    // mod_num keys
    $explode_mods  = explode(',', trim($_POST['mods']));
    
    // array to hold filenames
    $files_to_zip = array();
    
    // loop over all the mod_num keys submitted via POST
    foreach($explode_mods as $key){
        // save the filename to the corresponding array
        $files_to_zip[] = $mod_nums[$key];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have always and will continue to always close an HTML input such as
I have always used either a <br /> or a <div/> tag when something
I have always used this code to donwload the html source from a web
I have always used XML for returning data from my servlets and i have
I have always been taught to have one exit from functions and write code
Arrays have always been my downfall in every language I've worked with, but I'm
I have always used this code to send email from contact form of websites
I have always used TurtoiseSVN but this time I want to checkout code from
I have always missed a traverse function in jQuery, and I thinking that there
I have always had issues with identifying the errors in applications from the error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.