NikkiLoveGod Posted March 28, 2008 Share Posted March 28, 2008 Hi all! I'm having a small problem here, I dont remember how did those pointer to some part of memory worked. Had something to do with &-sign, I think. Here is my code and problem. I want to make this part here alot shorter and more efficient with the memorything(I think). I want this to be in ~2 foreaches, one for $_SESSION['mitat']and one for $_SESSION['kaltevuudet']. As the only thing that changes is the path to a different array, I want to make it so i can put it like "$path = $_SESSION['ulokkeet'][$indexi]['mitat'][$key]" ( note that there are two variables that are assigned by the foreach ). Is this possible, if it is, how? <?php if ( $_POST['uloke'] != '' ) { $uloke = $_POST['uloke']; $indexi = count($_SESSION['ulokkeet']); $_SESSION['ulokkeet'][$indexi]['id'] = $uloke; foreach($_SESSION['mitat'] as $key => $value) { $_SESSION['ulokkeet'][$indexi]['mitat'][$key] = str_replace(',', '.', $_POST[$key]); $$key = $_SESSION['paakatto']['mitat'][$key]; } foreach($_SESSION['kaltevuudet'] as $key => $value) { $_SESSION['ulokkeet'][$indexi]['mitat'][$key] = str_replace(',', '.', $_POST[$key]); $$key = $_SESSION['paakatto']['mitat'][$key]; } } elseif ( $_POST['uloke'] == '' ) { $_SESSION['paakatto']['mitat'] = NULL; foreach($_SESSION['mitat'] as $key => $value) { $_SESSION['paakatto']['mitat'][$key] = str_replace(',', '.', $_POST[$key]); $$key = $_SESSION['paakatto']['mitat'][$key]; } foreach($_SESSION['kaltevuudet'] as $key => $value) { $_SESSION['paakatto']['mitat'][$key] = str_replace(',', '.', $_POST[$key]); $$key = $_SESSION['paakatto']['mitat'][$key]; } } ?> ps. Sorry if it is a bit obfuscated I usually comment it when its done Link to comment https://forums.phpfreaks.com/topic/98278-cant-recall-how-the-pointers-to-memorypoint-work-any-help/ Share on other sites More sharing options...
NikkiLoveGod Posted March 28, 2008 Author Share Posted March 28, 2008 I think I MAY be referring to variable variables that i am even using there, but during a few tests, this doesnt work: <?php $_SESSION['test']['kala'] = 'LOL'; $path = '$_SESSION["test"]["kala"]'; $$path = 'test'; echo $_SESSION["test"]["kala"]; ?> it still echoes 'LOL'. Nor does it work with $path = '_SESSION["test"]["kala"]'; Looks like I have something to learn here >_< Link to comment https://forums.phpfreaks.com/topic/98278-cant-recall-how-the-pointers-to-memorypoint-work-any-help/#findComment-502962 Share on other sites More sharing options...
Cep Posted March 28, 2008 Share Posted March 28, 2008 Of course its going to echo LOL that is still the value of your session index which you set on line 1. What your next two lines have done, will not affect the echo statement at the end because that's not what your echoing. Link to comment https://forums.phpfreaks.com/topic/98278-cant-recall-how-the-pointers-to-memorypoint-work-any-help/#findComment-503108 Share on other sites More sharing options...
ysamu Posted March 28, 2008 Share Posted March 28, 2008 Try this: <?php $_SESSION['test']['kala'] = 'LOL'; $kala = &$_SESSION["test"]["kala"]; //Cretae pointer kala $kala = 'test'; echo $_SESSION["test"]["kala"]; ?> Link to comment https://forums.phpfreaks.com/topic/98278-cant-recall-how-the-pointers-to-memorypoint-work-any-help/#findComment-503147 Share on other sites More sharing options...
NikkiLoveGod Posted March 31, 2008 Author Share Posted March 31, 2008 Try this: <?php $_SESSION['test']['kala'] = 'LOL'; $kala = &$_SESSION["test"]["kala"]; //Cretae pointer kala $kala = 'test'; echo $_SESSION["test"]["kala"]; ?> THANK YOU, ysamu! I was sure it had something to do with the &-sign! We had a 2 minute lesson about this in school, but I couldnt remember it, and dont know what this is called Thanks a bunch! Link to comment https://forums.phpfreaks.com/topic/98278-cant-recall-how-the-pointers-to-memorypoint-work-any-help/#findComment-505408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.