How can GET variables be passed and called in PHP?
GET variables can be passed in a URL as key-value pairs and accessed in PHP using the $_GET superglobal array. To pass GET variables, simply append them to the URL after a question mark (?), separated by ampersands (&). In PHP, you can access these variables by referencing their keys in the $_GET array.
// Example of passing and accessing GET variables in PHP
// URL: http://example.com/index.php?name=John&age=30
$name = $_GET['name']; // Retrieves the value of 'name' variable
$age = $_GET['age']; // Retrieves the value of 'age' variable
echo "Name: $name, Age: $age"; // Outputs: Name: John, Age: 30
Keywords
Related Questions
- How can relative paths in PHP scripts be handled to ensure consistent behavior when run through different methods?
- What are some best practices for handling optional fields in PHP forms to prevent error messages?
- What potential issues can arise when trying to identify and add newly added files to a database using PHP?