This tutorial explains how to use the extract function in PHP on an array. The extract function is used to turn array elements into variables. It works on only associative arrays – the key becomes the variable name and the value for that key becomes the value of the new variable. Watch the video below and then scroll down for the sample code.
Sample PHP code:
<?php // The extract function turns array elements into variables // It works on associative arrays - the key becomes the variable name // and the value for that key becomes the value of the new variable. $characters = array('hero'=>'batman','villain'=>'joker'); extract($characters); echo $hero , "</br>"; echo $villain ?>