...

View Full Version : Resolved Automating Variables



ninnypants
03-09-2009, 08: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?

Iszak
03-09-2009, 08:36 PM
Something like...


<?php

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

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

echo $jim; // Output 1


or


<?php

$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