View Full Version : Resolved Automating Variables

03-09-2009, 07:13 PM
Is there a way to use one variables value as a variable name without code like

if($row['user_name'] == 'Jim'){
$jim = $row['user_id'];
if($row['user_name'] == 'ninnypants'){
$ninnypants = $row['user_id'];

This is all well and good since I would know what the usernames I'm pulling out are, but is there a way to automate this so that I wouldn't have to write so many if statements?

03-09-2009, 07:36 PM
Something like...


$row['user_id'] = 1;
$row['user_name'] = 'Jim';

${strtolower($row['user_name'])} = $row['user_id'];

echo $jim; // Output 1



$row['user_id'] = 1;
$row['user_name'] = strtolower('Jim');

$$row['user_name'] = $row['user_id'];

echo $jim; // Output 1

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum