extract() in PHP
By: Dietricha
If you compiled with "--enable-track-vars" then an easy way to get variable function args is to use extract().
<?php
$args = array("color" = "blue","number" = 3);
function my_func($args){
extract($args);
echo $color;
echo $number;
}
?>
the above strategy makes it real easy to globalize form data within functions, or to pass form data arrays to functions:
<input type="text" name="test[color]" value="blue">
etc, etc.
Then in your function, pass $test to extract() to turn the array data into global vars.
or
<?php
function my_func($HTTP_POST_VARS){
extract($HTTP_POST_VARS);
// use all your vars by name!
}
?>
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
PHP code to write to a CSV file for Microsoft Applications
PHP code to write to a CSV file from MySQL query
PHP code to import from CSV file to MySQL
Password must include both numeric and alphabetic characters - Magento
Error: Length parameter must be greater than 0
PHP file upload prompts authentication for anonymous users
PHP file upload with IIS on windows XP/2000 etc
Multiple File Upload in PHP using IFRAME
Resume or Pause File Uploads in PHP
Exception in module wampmanager.exe at 000F15A0 in Windows 8