Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-01-2005, 02:47 AM Variable Problem
Junior Talker

Posts: 2
Trades: 0
I have a loop where the variable $value is "Defence" the first time and "Attack" the second. Also, I have another variable at the same time $skill['Level'] which is 57 the first time and 65 the second. How do I do this:

$Defence_lvl = $Skill['Level'];
$Attack_lvl = $Skill['Level'];

The only thing is, is that I have to make these variable within the loop, so I have to use a command such as this:

$value_lvl = $Skill['Level']

I'm not sure on the correct syntax for that though or where the quotes are supposed to go or how the best method to do this is.
Daryl C is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-01-2005, 07:54 AM
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
An array index begins at 0, so to reference the 57th and 65th index and assign them to those vars, it'll look something along these lines..

$Defence_lvl = $Skill[56];
$Attack_lvl = $Skill[64;

As for you last request, It doesn't make sense. "$value_lvl = $Skill['Level']" is a statement that assigns a value to a variable. Please post the "loop" code that your referring to instead of snippets.
__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 06-01-2005, 09:30 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Use two dollar signs to control variable names:

PHP Code:

$value 
"Defence";

$name $value "_lvl";

$
$name $Skill['Level'];

echo 
$Defence_lvl;

$value "Attack";

$name $value "_lvl";

$
$name $Skill['Level'];

echo 
$Attack_Lvl
In the above example all this is not needed, but wrap that up in your loop and it ought to work.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 06-01-2005, 12:16 PM
Junior Talker

Posts: 2
Trades: 0
It works, finally.

It took a while for it to work though all because I missed a capital letter, but it finally works.

Final code on that

Code:
$name = $value . "_lvl";
$$name = $skill['Level'];
Thanks for the help
Daryl C is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Variable Problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20847 seconds with 12 queries