variable array

Thread Solved

Join Date: Jun 2008
Posts: 848
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 68
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

variable array

 
0
  #1
Jun 13th, 2008
I have a large multidimentional array that I am looping through to change it's structure and theoretically this function will work accept the "variable array" part. And maybe that's not the right name for it as I have checked my resources and cannot come up with the right syntax for it but theoretically, I think I should be able to do it.

If you know what a variable variable is:
  1. $variable = "blue";
  2. $$variable = "red";
  3.  
  4. //what you get is
  5. $blue = "red";

I am trying to do the same thing with an array:
  1. $variable = "blue";
  2. $$variable[] = "red";
  3.  
  4. //what I want is
  5. $blue[0] = "red";

Does that make sense?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,234
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 170
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: variable array

 
1
  #2
Jun 13th, 2008
the syntax you are looking for is:

  1. $variable = "blue";
  2. ${$variable}[] = "red";
  3.  
  4. //print array to see if it worked (did for me)
  5. print_r(${$variable});
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 848
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 68
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: variable array

 
0
  #3
Jun 13th, 2008
Sweet, that's the ticket, thx.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1004 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC