GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jul-2005, 08:35
raisinlove raisinlove is offline
New Member
 
Join Date: Jul 2005
Posts: 1
raisinlove is on a distinguished road

generating arrays from main multi-dimensional array


Hi!
For a list of projects, I have no access to a database, so I decided to create a folder for each project. The names of these folders are meant to categorize the projects by client and media:

PHP Code:

$projects = array(
                'media01-client1-project01_1',
                'media01-client1-project01_2',
                'media01-client2-project01_1',
                'media01-client2-project01_2',
                'media01-client2-project01_3',
                'media02-client3-promo02_1',
                'media02-client1-promo02_1',
                'media02-client4-promo02_1',
                'media02-client4-promo02_2',
                'media03-client3-project03_1',
                'media03-client3-project03_2',
                'media03-client2-project03_1',
                'media03-client2-project03_2',
                'media03-client2-project03_3',
                'media04-client1-project04_1',
                'media04-client4-project04_1',
                ) 



I asked on another forum how I could create individual arrays out of this one using the dash delimiter from the strings. i was given the following:

PHP Code:

foreach ($projects as $value)
{
    $explode = explode('-', $value);
    $multi_projects[$explode[0]][$explode[1]][] = $explode[2];
} 



But how do I use this to generate arrays for the media and clients?

I.E.:

PHP Code:

$media = array(
                'media01',
                'media02',
                'media03',
                'media04',
                )


$clients = array(
                'client1',
                'client2',
                'client3',
                'client4',
                ) 



What I would then like to do is generate sub-arrays of related projects per media or client.

I.E.:

PHP Code:

$projects_by_media = array(
                'media01=>array(
                                'media01-client1-project01_1',
                                'media01-client1-project01_2',
                                'media01-client2-project01_1',
                                'media01-client2-project01_2',
                                'media01-client2-project01_3'
                                )',
                'media02=>array(
                                'media02-client3-promo02_1',
                                'media02-client1-promo02_1',
                                'media02-client4-promo02_1',
                                'media02-client4-promo02_2'
                                )',
                'media03=>array(
                                'media03-client3-project03_1',
                                'media03-client3-project03_2',
                                'media03-client2-project03_1',
                                'media03-client2-project03_2',
                                'media03-client2-project03_3'
                                )',
                'media04=>array(
                                'media04-client1-project04_1',
                                'media04-client4-project04_1'
                                )'
                )


$projects_by_clients = array(
                'client1=>array(
                                   'media01-client1-project01_1',
                                'media01-client1-project01_2',
                                'media02-client1-promo02_1',
                                'media04-client1-project04_1'
                                )',
                'client2=>array(
                                   'media01-client2-project01_1',
                                'media01-client2-project01_2',
                                'media01-client2-project01_3',
                                'media03-client2-project03_2',
                                'media03-client2-project03_3'
                                )',
                'client3=>array(
                               'media02-client3-promo02_1',
                               'media03-client3-project03_1',
                               'media03-client3-project03_2'
                                )',
                'client4=>array(
                               'media02-client4-promo02_1',
                               'media02-client4-promo02_2',
                               'media04-client4-project04_1'
                                )'
                ) 


Last edited by LuciWiz : 08-Jul-2005 at 08:38. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 25-Jul-2005, 12:29
agraddy agraddy is offline
New Member
 
Join Date: Jul 2005
Posts: 2
agraddy is on a distinguished road
You could use a regular expression match (preg_match() would be a possible function) and create a media array and a client array by looping through the original array and returning all of the matches.

If you are not familiar with regular expressions, then here is a good website that helped to get me started: weblogtoolscollection.com

Hope this helps.
Last edited by admin : 26-Jul-2005 at 01:28. Reason: Please set up signature in your profile only.
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic allocation of multi dimensional array pointer C Programming Language 7 13-May-2005 23:50
Noob question on c arrays and functions brett C Programming Language 1 20-Apr-2005 03:59
template comiling problems - need expert debugger! crq CPP / C++ Forum 1 01-Feb-2005 21:26
Creating N string gwk C Programming Language 3 20-Jul-2004 23:27

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:16.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.