Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP How to compact my variables into a FOR loop?
    text
    copied!<p>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.</p> <p><strong>HERE ARE MY VARIABLES</strong></p> <pre><code> $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); </code></pre> <p><strong>HERE IS WHAT I HAVE TRIED</strong></p> <pre><code>for($i = 0; $i&lt;20; $i++) { $saveData = '$saveData_'.$i; $postData = 'post_data($url_'.$i.')'; print($saveData. '=' .$postData. ';'); } </code></pre> <p>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.</p> <p>Basically my goal is to write the Variables of above without having to actually write a new variable each time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload