Re: Creating variable names from values

From: Date: Thu, 08 Mar 2007 17:21:43 +0000
Subject: Re: Creating variable names from values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-250094@lists.php.net to get a copy of this message
----- Original Message ----- From: "Otto Wyss" <otto.wyss@orpatec.ch> To: <php-general@lists.php.net> Sent: Thursday, March 08, 2007 5:56 PM Subject: [PHP] Creating variable names from values
From an arry I create a table like foreach ($persons as $key => $pers) {
    echo "<td><input name=\"K$key\" type=\"checkbox\" ...></td>
          <td>...</td>
} so each checkbox field has its own name created from $key. Yet how can I access these fields (names) later on? foreach ($persons as $key => $pers) {
$key = 'K' . $key; if ($$key) { notice double dollar sign, it means, not the value of $key but the value of the variable $key says.
    if ($K???) {
      $cnt += 1; ...
    }
} Is there a better way to access multiple fields from a table? O. Wyss -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date: 07/03/2007 9:24


« previous php.general (#250094) next »