How can you pass a variable as the $_POST array key value in PHP? Or is it not possible?
$test = \"test\";
echo $_POST[$test];
Thanks
If I get you right, you want to pass a variable from one php-file to another via post. This sure is possible in several ways.
1. With an HTML-form
if you click on the submit-button, $_POST['key']
in target.php
will contain 'foo'
.
2. Directly from PHP
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: text/html\r\n",
'content' => http_build_query(array('key' => 'foo'))
),
));
$return = file_get_contents('target.php', false, $context);
Same thing as in 1., and $return
will contain all the output produced by target.php
.
3. Via AJAX (jQuery (JavaScript))
Same thing as in 2., but now data
contains the output from target.php
.