razormedia Posted October 9, 2011 Share Posted October 9, 2011 I haven't posted here before but I am completely stuck. I've checked everywhere and cannot find answer to this question. I have an array and if I were to do this: echo $partNames[$jjk]; it would return another part of an array as such: $decoded[0]["Parts"][3]["BodyPart"] (if I retrieve type, this is a string). Now, I need to return the actual value from particular array reference and I cannot for the life of me do it and its destroying my will to live. i've tried combinations of: echo $partNames[$jjk]; echo $$partNames[$jjk]; echo ${$partNames[$jjk]}; echo ${$partNames}[$jjk]; $sssttt = substr($partNames[$jjk], 1); echo $sssttt.' - '.${$sssttt}; Yet nothing seems to work. Solution is to rewrite whole script but this is now pretty complicated parser and I do not want to rewrite sections as deadlines are looming. Any help would be appreciated. (I'm new but i'll try to help others now in anticipation of help). Cheers Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/ Share on other sites More sharing options...
razormedia Posted October 10, 2011 Author Share Posted October 10, 2011 Please don't make me rewrite it. I assume the answer is staring me in the face but I cannot see it. Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277688 Share on other sites More sharing options...
salathe Posted October 10, 2011 Share Posted October 10, 2011 I assume the question is staring me in the face but I cannot see it. What exactly is contained in the variables $jjk, $partNames and $decoded? Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277689 Share on other sites More sharing options...
razormedia Posted October 10, 2011 Author Share Posted October 10, 2011 apologies salathe, let me try to clarify: $partNames is an array $jjk is just numeric (used in for loop) $decoded is an array so for example, $partnames is an array of strings which I want as references to another array; ie: $partNames[0] = "$decoded[0]["Parts"][3]["BodyPart"]"; its how to use this string as a reference to the particular value held in $decoded[0]["Parts"][3]["BodyPart"] thats the question. make sense or still confusing? Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277706 Share on other sites More sharing options...
razormedia Posted October 10, 2011 Author Share Posted October 10, 2011 initially I would have thought: $$partnames[0] would give me the value of the decoded array but it doesn't seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277707 Share on other sites More sharing options...
Buddski Posted October 10, 2011 Share Posted October 10, 2011 eval() Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277709 Share on other sites More sharing options...
Muddy_Funster Posted October 10, 2011 Share Posted October 10, 2011 wouldn't it make more senese to change $partNames to a multidimensional array? Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277716 Share on other sites More sharing options...
razormedia Posted October 10, 2011 Author Share Posted October 10, 2011 eval won't work with arrays as I'm also using [] therefore eval($partNames[$jjk] will never work. multidimensional array - possibly I may need to rewrite parts of this to store values rather than whole array references in mda). Quote Link to comment https://forums.phpfreaks.com/topic/248766-referencing-variables/#findComment-1277737 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.