Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-20-2002, 09:17 PM
Dragomancer's Avatar
Dragomancer Dragomancer is offline
 
Join Date: Jan 2002
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 05-20-2002, 09:32 PM
Superbronx's Avatar
Superbronx Superbronx is offline
 
Join Date: Mar 2002
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 05-20-2002, 09:46 PM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Reply With Quote
  #4  
Old 05-21-2002, 08:57 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Read all about variable variables here:
http://www.php.net/manual/en/languag...s.variable.php
Reply With Quote
  #5  
Old 05-21-2002, 12:06 PM
Dragomancer's Avatar
Dragomancer Dragomancer is offline
 
Join Date: Jan 2002
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 05-21-2002, 12:27 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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); 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:21 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04463 seconds
  • Memory Usage 2,214KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete