Python Forum
Best way to accommodate unknown number of variables?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to accommodate unknown number of variables?
#8
Well, maybe dynamically generated variables is something for a future version of Python, because, in PHP, that is a) possible and b) very handy!

This dynamically generates data arrays for output in html tables.

The number of questions varies from time to time. Like the OP said, I don't know or care how many questions there are each time.

But, of course, the whole output.html.php file is generated using Python and couple of text files!

Quote:if(isset($_POST['studentnum'])) {
$count = count($questions);
for($i=1; $i<=$count; $i++) {
//echo '$i is ' . $i . '<br>';
$Qnr = 'Q' . $i;
//echo '$Qnr = ' . $Qnr . '<br>';
${'Q'.$i} = $questions[$i-1];
// should be an array of 3 arrays, 3 results, 1 for each gender
${"men$i"} = displayAllQs($Qnr);
//echo 'This is ${"men$i"} <br>';
//$name = 'men' . $i;
//echo 'results array is ' . $name . '<br>';
//print_r(${"men$i"});
//echo '<br>';
${"menP$i"} = displayAllQs($Qnr);
$lenmenP = count(${"menP$i"});
Reply


Messages In This Thread
RE: Best way to accommodate unknown number of variables? - by Pedroski55 - May-22-2022, 11:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create X Number of Variables and Assign Data RockBlok 8 1,045 Nov-14-2023, 08:46 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020