vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Variable in a Variable ? (https://vborg.vbsupport.ru/showthread.php?t=38853)

Dragomancer 05-20-2002 09:17 PM

Variable in a Variable ?
 
Hi,
I'm currently working with a html-form, and I've got a lot of variables to work through. Because the form is generated dynamicly, I don't know how many variables I'll get. My code is looking like this:

PHP Code:

if($test1==1){
 ...}
if(
$test2==1){
 ...}
if(
$test3==1){
 ...}
if(
$test4==1){
 ...}
if(
$test5==1){
 ...} 

Could someone please help by tell me how to combine '$test' into a "double" variable, so it would somehow look like this:

PHP Code:

$count=1;
while(isset(
$test$count)){
 if (
$test$count==1){
  ....
 }
 
$count++;


Thanks for your help.

Superbronx 05-20-2002 09:32 PM

If your talking about arrays, this is what you would do -

$test[$count]

If your talking about combining the string, this is what you would do -

$another_variable = ($test).($count)

Hope that helped.

Mark Hensler 05-20-2002 09:46 PM

PHP Code:

$count=1;
while(isset(${
"test".$count})){
 if (${
"test".$count}==1){
  ....
 }
 
$count++;



Admin 05-21-2002 08:57 AM

Read all about variable variables here:
http://www.php.net/manual/en/languag...s.variable.php

Dragomancer 05-21-2002 12:06 PM

Quote:

Originally posted by Mark Hensler
PHP Code:

$count=1;
while(isset(${
"test".$count})){
 if (${
"test".$count}==1){
  ....
 }
 
$count++;



Thanxs, that's what i was looking for.

Admin 05-21-2002 12:27 PM

Since it's a POSTed form, you can also use the $_POST array ($HTTP_POST_VARS for older PHP versions).

PHP Code:

foreach ($_POST as $variable => $value) {
    
// $variable would be 'test1', 'test2', 'test3', 'test4' etc.
    // And $value would be whatever the user entered in the form


Use print_r() to see exactly what the $_POST array contains, and see how it can be useful:
PHP Code:

print_r($_POST); 



All times are GMT. The time now is 01:40 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01634 seconds
  • Memory Usage 1,731KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete