|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-05-16 04:18 UTC] illicitcriminal at gmail dot com
Description:
------------
I think it'd be VERY useful to be able to declare/state variables based on the value of another variable. I've run into situations where it would save me a bit of time if this were possible.
In "Reproduce Code", I'll show you a piece that would be useful for an encryption function that I wrote.
Reproduce code:
---------------
/*
Giving Letters Numerical Values
*/
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$length = strlen($alphabet);
for ($cur=0;$cur<$length;$cur++){
$letter = substr($alphabet, $current, $current+1);
$numberVal = $current+1;
/*
This is where my idea comes in to play.
To be able to name the variable "a",
referred to as $a (and b,c,d so on...).
I've used the syntax ^$var to define the naming
of the variable dependant on the value of
$var (another variable)...
*/
^$letter = $numberVal;
}
echo $a.'-'.$b.'-'.$c.'-'.$A.'-'.$B.'-'.$C;
Expected result:
----------------
1-2-3-26-27-28
Actual result:
--------------
Probably an "unexpexted '^'" parse error.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 09:00:01 2025 UTC |
Already possible: <?php $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $length = strlen($alphabet); for ($i = 0; $i<$length; $i++) { $$alphabet{$i} = $i; } echo $a.'-'.$b.'-'.$c.'-'.$A.'-'.$B.'-'.$C; ?> result = 0-1-2-26-27-28