pcmad Posted January 9, 2011 Share Posted January 9, 2011 i am trying to build a payment gate way library do you think this is the best way of going about it requirements code to be flexible for different naming conventions to conform with standards not to break why i am thinking of doing it this way one application could have for addressline1 as add_1 while i different app will have it as add_line_1 $test2 = "yay"; $test = 'a:1:{s:6:"teatme";s:5:"test2";}'; // think of this a a db field $test = unserialize($test); echo"<pre style=\"text-align:left;\">"; print_r($test); echo"</pre>"; foreach ($test as $key => $value) { $test[$key] = $$value; } echo"<pre style=\"text-align:left;\">"; print_r($test); echo"</pre>"; please give us your thoughts Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/ Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 instead of the foreach loop, you can use one command extract($test); Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157049 Share on other sites More sharing options...
pcmad Posted January 9, 2011 Author Share Posted January 9, 2011 no that wont work because the that values and variables that will be stored back into the array eg $test2 = "yay"; foreach { $test[$key] = $$value; becomes $test[$key] = $test2; becomes $test[$key] = "yay"; } Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157051 Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 it seems you are simply looping over the array and setting each value to itself. exactly what are you trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157053 Share on other sites More sharing options...
pcmad Posted January 9, 2011 Author Share Posted January 9, 2011 flexibility and uniformity basicy the loop is populating the array with data from the application but some applications might not have the same variables once array it processed it will then be set off to a payment gate way Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157054 Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 i think i understand. the field names are stored in the database and the loop set's the variable names and values based on the stored variable names. i haven't had to program anything like this, so i have no opinion on the method except "it looks fine to me." Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157056 Share on other sites More sharing options...
ignace Posted January 9, 2011 Share Posted January 9, 2011 no that wont work because the that values and variables that will be stored back into the array You don't need to store it back into the array. The array will still be intact after you looped over it So like BlueSkyIS showed extract will be fine. Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157057 Share on other sites More sharing options...
pcmad Posted January 9, 2011 Author Share Posted January 9, 2011 i do need to store in back in to the array the arrz\value need is a reference to the true data Quote Link to comment https://forums.phpfreaks.com/topic/223874-does-this-conform-with-standard-and-will-it-break/#findComment-1157063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.