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 9095777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:41:25+00:00 2026-06-16T23:41:25+00:00

I have a list of variables which I am using for some PHP functions.

  • 0

I have a list of variables which I am using for some PHP functions. I know I can simplify this code but I am not really sure how. I have tried for(){} loops but haven’t figured out how to make the result usable.

HERE ARE MY VARIABLES

    $saveData_1  = post_data($url_1);
    $saveData_2  = post_data($url_2);
    $saveData_3  = post_data($url_3);
    $saveData_4  = post_data($url_4);
    $saveData_5  = post_data($url_5);
    $saveData_6  = post_data($url_6);
    $saveData_7  = post_data($url_7);
    $saveData_8  = post_data($url_8);
    $saveData_9  = post_data($url_9);
    $saveData_10 = post_data($url_10);
    $saveData_11 = post_data($url_11);
    $saveData_12 = post_data($url_12);
    $saveData_13 = post_data($url_13);
    $saveData_14 = post_data($url_14);
    $saveData_15 = post_data($url_15);
    $saveData_16 = post_data($url_16);
    $saveData_17 = post_data($url_17);
    $saveData_18 = post_data($url_18);
    $saveData_19 = post_data($url_19);
    $saveData_20 = post_data($url_20);

HERE IS WHAT I HAVE TRIED

for($i = 0; $i<20; $i++) {
        $saveData = '$saveData_'.$i;
        $postData = 'post_data($url_'.$i.')';   
        print($saveData. '=' .$postData. ';');
    }

This works for the most part, it prints out my list of variables. But what I don’t know, is how to make this usable so instead of printing them to the page being displayed in the browser they will be instead be “printed” to my php script.

Basically my goal is to write the Variables of above without having to actually write a new variable each time.

  • 1 1 Answer
  • 0 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-06-16T23:41:27+00:00Added an answer on June 16, 2026 at 11:41 pm

    You need to use arrays. I will type up an example and add it to this comment. But what you want to use is an array variable. One array can hold all this and you can iterate (loop) through it easily.

    Here ya go:

    <?php
    /* what the heck?  You need arrays ;-)
    $saveData_1  = post_data($url_1);
    $saveData_2  = post_data($url_2);
    $saveData_3  = post_data($url_3);
    $saveData_4  = post_data($url_4);
    $saveData_5  = post_data($url_5);
    $saveData_6  = post_data($url_6);
    $saveData_7  = post_data($url_7);
    $saveData_8  = post_data($url_8);
    $saveData_9  = post_data($url_9);
    $saveData_10 = post_data($url_10);
    $saveData_11 = post_data($url_11);
    $saveData_12 = post_data($url_12);
    $saveData_13 = post_data($url_13);
    $saveData_14 = post_data($url_14);
    $saveData_15 = post_data($url_15);
    $saveData_16 = post_data($url_16);
    $saveData_17 = post_data($url_17);
    $saveData_18 = post_data($url_18);
    $saveData_19 = post_data($url_19);
    $saveData_20 = post_data($url_20);
    */
    
    
    
    $saveData = array();  // just a formality. You don't need to delcare variable types in PHP.
    for ($i = 1; $i < 21; $i++) {
        $var = 'url_'.$i;
        $saveData[$i] = post_data($$var);
    }
    
    // now all your stuff is in $saveData
    // what's in savedata 20?  this is:
    echo $saveData[20];
    
    // you could skip all of this and just use the $_POST superglobal
    $_POST[$url_20]
    
    // I'm curious to see what you are doing, because this process should be re-thought.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP code which I am using to display the list of
I have some PHP on my site which contains the following portion of code:
I have a list of variables: variables = ['VariableA', 'VariableB','VariableC'] which I'm going to
I have list view and its adapter stored as global variables. I am not
Using introspection In Flex I can say: var classInfo:XML=describeType(SomeObject); Which will list for me
I have some php code for running a different mySQL queries based on an
I'm new to using Java, but I have some previous experience with C#. The
Using CakePHP 1.3.6 I'm sure I may have to add code and examples, but
I have some php code that is pretty much being duplicated save for some
For some years that I've been using my own PHP template engine, which is

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.