User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,310 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,286 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Dynamic Declaration of Arrays Keys

Join Date: Feb 2008
Posts: 4
Reputation: monkey56657 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
monkey56657 monkey56657 is offline Offline
Newbie Poster

Re: Dynamic Declaration of Arrays Keys

  #2  
Feb 12th, 2008
Can you explain again exactly what you want with better examples. I get all of what your saying but dont get exactly what your looking for.

Provides a few array b4 and afters or something.

Okay I am going to have a random guess firstly and hope this is what you want.

Okay we imagine an array called $content. The piece of data we want could be in any of the following

$content[0]
$content[0][0]
$content[0][0][0]
$content[0][0][0][0]
$content[0][0][0][0][0]

But all the keys you know. Firstly we assume that all the keys are 0 and we want to follow all of the 0 keys until we find a key that is not an array?

Then we can do the following
  1. function array_flow($array)
  2. {
  3. if (is_array($array[0]))
  4. {
  5. array_flow($array[0]);
  6. }
  7. else
  8. {
  9. return ($array[0]);
  10. }
  11. }
Which can easily be used as below...
  1. echo array_flow($content);
Now if we assume that the array key isnt always 0 but always remains constant then we can add to the original function as below...
  1. function array_flow($array,$key)
  2. {
  3. if (is_array($array[$key]))
  4. {
  5. array_flow($array[$key]);
  6. }
  7. else
  8. {
  9. return ($array[$key]);
  10. }
  11. }
And using it would differ slightly....
  1. echo array_flow($content,1);
In the new example we use 1 as the key so we could find the value of

$content[1] all the way to $content[1][1][1][1][1] and beyond.

I really hope this is what you are looking for. If not you can contact me via IM or something...

All my contact info can be found here http://profiles.web-starters.net/monkey56657
Last edited by monkey56657 : Feb 12th, 2008 at 6:26 pm.
Reply With Quote  
All times are GMT -4. The time now is 10:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC