PHP Tutorial : Extract function

A shame for me but I must tell you this function called extract() simply rocks : it will extract “keys” from an array and convert them into variables, so no more needed to manually declare variables for validation purposes from forms.

<form action="" method="post">
name <input type="text" name="name"><br/>
email <input type="text" name="email"><br/>
<input type="submit" name="sb" id="sb" value="go">
</form>
<?php

if(isset($_POST['sb'])) {
extract($_POST);

if(empty($name) || empty($email)) die("email and name emtpy");

print "Name is $name and email is $email now!";
}
?>
This entry was posted in Usefull PHP and tagged , , . Bookmark the permalink.

3 Responses to PHP Tutorial : Extract function

  1. KeHoeff says:

    hey this is a very interesting article!

  2. bogdan says:

    I must admit I’d not encountered this function before, didn’t know it existed. Should prove useful, so thanks.

  3. admin says:

    me too here, just discovered it, isn’t it a nice one?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>