On Thursday, April 11, 2002, at 08:52  AM, ROBERT MCPEAK wrote:

> This has jump started me.  How do I grab only certain variables, for
> example, only vars named "doh," or, better yet, only vars containing
> "doh?"  I have check box vars named 4-1, 4-2, 4-3, 4-4, etc., and I wish
> to stick them together in a string, but only those vars, no others.
> Is there a smarter way to do this?

You do the exact same thing, but you put an if statement in your loop so 
that IF the var is what you are looking for, add it to the array.  I 
have appended the original code I sent you to the end of this email, and 
if you look carefully at the foreach loop, it is exactly the same thing 
except now there is an if statement in it.

To list all the POST variables that contain "doh", you would do this:

$post_array = array();
foreach ($_POST as $post_variable) {
   if ($post_variable == "doh") {
     $post_array[] = $post_variable;

You don't need an else statement, since the loop will just continue if 
the value of the variable is not "doh".



Erik Price
Web Developer Temp
Media Lab, H.H. Brown

$return_path_arr = array();  // initialize the array to temporarily
store GET vars
$return_path_str = "";  // initialize the string to store GET vars

// this loops through all GET vars and assigns their names to
// and their values to $getvarvalue in each iteration of the loop
foreach ($_GET as $getvarname => $getvarvalue) {

      // create the name-value pair
      $return_path_arr[] = $getvarname . "=" . $getvarvalue;

// take each name-value pair and implode it into one big string,
// with each pair separated by '&'
$return_path_str = implode("&", $return_path_arr);

// later, I stick this string into a hidden form field so that I have
// my own custom "back" button where I will need it
echo "<input type=\"hidden\" name=\"returnpath\"
value=\"$return_path_str\" />";

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to