Archive

Posts Tagged ‘foreach’

convert array keys to variable

October 10th, 2009 Jigish Thakar 4 comments
php code 300x193 convert array keys to variable

few days back i was working on opencart ecommerce software. and found something nice.

bcasically this software build on PHP MVC framework, so what they have done is took all the values in one array called “data”, which user need to see on browser

and then while sending it to its template file they converted the whole data array to variables

like

$data['first_name'] = "jigish";

so in template file you ll get it as

$first_name and its value is “jigish”

so now how you do it

its nothing big magic just a simple two line of code

foreach($data as $k => $v)
$$k = $v;

isnt it very simple?

Dropdown with the file names

October 24th, 2008 sagar 3 comments

hii guys today i came across a problem wherein i had to fill in a dropdown menu with all the file names in a particular folder. and this is wat i hav got from a free source and believe me guys this is as simple as you can imagine.. Read more…