Jump to content

Variable variables


darkhappy

Recommended Posts

I am getting an error when processing this code - could anyone give me the proper syntax/puntuation for this?

 

 

 

<?php
while ($a = mysql_fetch_array($approvals)) {

             if(isset($_POST['{$a['approvals']}'])) {
                          $sheetid = $_POST['{$a['approvals']}'];
                          }
             }
?>

Link to comment
https://forums.phpfreaks.com/topic/105192-variable-variables/
Share on other sites

Try this:

 

<?php
while ($a = mysql_fetch_array($approvals)) {

             if(isset($_POST[$a['approvals']])) {
                          $sheetid = $_POST[$a['approvals']];
             }
}
?>

 

The syntax for how you were trying to do it is like this:

 

$val =  "{$a['approvals']}";

Link to comment
https://forums.phpfreaks.com/topic/105192-variable-variables/#findComment-538635
Share on other sites

i will have to try that next time... instead i tweaked this function to pull the key out of the variable once it is posted. lots of work for a 1 little number hehe!

 

 

<?php
function get_sheet() {
$context = '_POST';

global $$context;
if(isset($$context)) {
        foreach($$context as $k => $v) {
                $sheetid = $k;
                }
        }
}
get_sheet();
?>

Link to comment
https://forums.phpfreaks.com/topic/105192-variable-variables/#findComment-538641
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.