473,246 Members | 1,433 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

array key reassignment methodology

I would like some assistance in methodology to reassign/reset array keys to
consecutive numbering, while keeping in sync a second array that uses the
key of the first as it's key set.

If I have read a solution on php.net, I didn't understand what I was
reading.
At this stage of bumbling around, I am getting rather confused/frustrated.
...and getting mind around multidimensional arrays hurts :)

*** note php4 only available ***
$links is used to generate main page links.
$gallery is used to generate links on the $links page that has the same key
value.

The output below was produced using my config generator form, which enables
adding/deletion of links and associated galleries, which accounts for the
gaps in the $links key.

///// LINK LIST (TOP OF PAGE LINKS) /////
$links[0]=array('home'=>'Home');
$links[1]=array('service'=>'Services');
$links[3]=array('people'=>'Portraits');
$links[5]=array('fundraise'=>'Fundraise');
$links[6]=array('events'=>'Events');
$links[7]=array('contact'=>'Contact');
///// GALLERY LIST /////
$gallery[0]=array('service'=>'Service','reception'=>'Receptio n');
$gallery[3]=array('family'=>'Family','children'=>'Children',' adults'=>'Adult
s');
$gallery[5]=array('cards'=>'Cards','leaflets'=>'Leaflets');



Aug 12 '05 #1
8 1833

"PhilM" <ph***@nospam.com.am> wrote in message
news:42**********************@news.optusnet.com.au ...
I would like some assistance in methodology to reassign/reset array keys to consecutive numbering, while keeping in sync a second array that uses the
key of the first as it's key set.
*** note php4 only available ***
$links is used to generate main page links.
$gallery is used to generate links on the $links page that has the same key value.

The output below was produced using my config generator form, which enables adding/deletion of links and associated galleries, which accounts for the
gaps in the $links key.

///// LINK LIST (TOP OF PAGE LINKS) /////
$links[0]=array('home'=>'Home');
$links[1]=array('service'=>'Services');
$links[3]=array('people'=>'Portraits');
$links[5]=array('fundraise'=>'Fundraise');
$links[6]=array('events'=>'Events');
$links[7]=array('contact'=>'Contact');
///// GALLERY LIST /////
$gallery[0]=array('service'=>'Service','reception'=>'Receptio n');
$gallery[3]=array('family'=>'Family','children'=>'Children',' adults'=>'Adult s');
$gallery[5]=array('cards'=>'Cards','leaflets'=>'Leaflets');

ok, this is what I eventually came up with... is there a smoother way?

$indexer=0;
foreach (array_keys($links) as $linkKey){
$collecter[$indexer]=$linkKey;
$indexer++;
}
foreach (array_keys($collecter) as $linkKey){
if ($links[$collecter[$linkKey]]){
$linksHolder[$linkKey]=$links[$collecter[$linkKey]];}
if ($gallery[$collecter[$linkKey]]){
$galleryHolder[$linkKey]=$gallery[$collecter[$linkKey]];}
}
$links=$linksHolder;$gallery=$galleryHolder;
Aug 12 '05 #2
First off, why is consecutive numbering important? It may or may not
be, depending on what you're trying to accomplish.

Why not just combine the two arrays into one to make life easier? For
instance, you might have something like:

$myArray[0]['links'] = array('home'=>'Home');
$myArray[1]['links'] = array('service'=>'Services');
$myArray[3]['links'] = array('people'=>'Portraits');
$myArray[5]['links'] = array('fundraise'=>'Fundraise');
$myArray[6]['links'] = array('events'=>'Events');
$myArray[7]['links'] = array('contact'=>'Contact');
///// GALLERY LIST /////
$myArray[0]['gallery'] =
array('service'=>'Service','reception'=>'Reception ');
$myArray[3]['gallery'] =
array('family'=>'Family','children'=>'Children','a dults'=>'Adult
s');
$myArray[5]['gallery'] =
array('cards'=>'Cards','leaflets'=>'Leaflets');

Then you can re-index the whole thing in a continuous way without
losing your link/gallery association:

$myArray = array_merge($myArray); //just re-indexes the array

Aug 12 '05 #3
First off, why is consecutive numbering important? It may or may not
be, depending on what you're trying to accomplish. Ultimately I want to be able to set the order in which the links appear on
the page. I figure taht it would be easier if they are in the array in the
correct order. I can then display the keys as the position, then reassign
keys on form return(submit).
Why not just combine the two arrays into one to make life easier? For
instance, you might have something like:

$myArray[0]['links'] = array('home'=>'Home');
$myArray[1]['links'] = array('service'=>'Services');
$myArray[3]['links'] = array('people'=>'Portraits');
$myArray[5]['links'] = array('fundraise'=>'Fundraise');
$myArray[6]['links'] = array('events'=>'Events');
$myArray[7]['links'] = array('contact'=>'Contact');
///// GALLERY LIST /////
$myArray[0]['gallery'] =
array('service'=>'Service','reception'=>'Reception ');
$myArray[3]['gallery'] =
array('family'=>'Family','children'=>'Children','a dults'=>'Adult
s');
$myArray[5]['gallery'] =
array('cards'=>'Cards','leaflets'=>'Leaflets');

Then you can re-index the whole thing in a continuous way without
losing your link/gallery association:

$myArray = array_merge($myArray); //just re-indexes the array


Why not indeed ;) Thx for that. Will have a go at it later.
Q:-
To determine if a gallery then exists, I assume I would just have to do
something like:-
if ($myArray[0]['gallery']){ do gallery stuff }
???
Aug 12 '05 #4
Sure, or to be very thorough, you could do:

if(is_array($myArray[0]['gallery'])) { //do gallery stuff }

Aug 12 '05 #5
Just create a new array using array_value(). The original array should
be left alone. Modifying configuration data in the middle of a program
is usually a bad idea.

Aug 12 '05 #6

"ZeldorBlat" <ze********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Sure, or to be very thorough, you could do:

if(is_array($myArray[0]['gallery'])) { //do gallery stuff }


thx again.
Aug 13 '05 #7
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Just create a new array using array_value(). The original array should
be left alone. Modifying configuration data in the middle of a program
is usually a bad idea.

Understood.
What I have set up though, is a config tool that will edit the configuration
file which is separated from the site. When editing is complete, requires a
form submit to transfer to the local site directory where the page can read
it. Then it needs to be uploaded to the live site via ftp.
Odd perhaps, but this whole project is aimed (from my point of view) to the
maintaining an accurate or advanced offline backup of the live site, by
someone who is not web savvy.
Aug 13 '05 #8
In article <42**********************@news.optusnet.com.au>, PhilM wrote:
I would like some assistance in methodology to reassign/reset array keys to
consecutive numbering, while keeping in sync a second array that uses the
key of the first as it's key set. adding/deletion of links and associated galleries, which accounts for the
gaps in the $links key.

///// LINK LIST (TOP OF PAGE LINKS) /////
$links[0]=array('home'=>'Home');
$links[1]=array('service'=>'Services');
$links[3]=array('people'=>'Portraits');
$links[5]=array('fundraise'=>'Fundraise');
$links[6]=array('events'=>'Events');
$links[7]=array('contact'=>'Contact');
///// GALLERY LIST /////
$gallery[0]=array('service'=>'Service','reception'=>'Receptio n');
$gallery[3]=array('family'=>'Family','children'=>'Children',' adults'=>'Adult
s');
$gallery[5]=array('cards'=>'Cards','leaflets'=>'Leaflets');


hmmm... gallery keys to stay synced with links keys?
something like this?

$n=0;
foreach ( $links as $key => $val ){
$links[$key]=NULL;
$links[$n]=$val;
$val=gallery[key];
$gallery[$key]=NULL;
$gallery$[$n]=$val;
$n++;
};

--

Bye.
Jasen
Aug 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: F. Da Costa | last post by:
Hi, Could it be correct that the following code does *not* work because i'm not using the var arr = new Array("a","b","c"); methodology?? Read through...
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
22
by: Ally | last post by:
Could someone give me an example of a modern development methodology? Just to see if I'm thinking along the right lines... P.S. Sorry for the cross posting but I couldn't find a newsgroup for...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
3
by: Daniel | last post by:
Hey guys i have a array of daya that i wish to iterate through. the only catch is i need to start from a certain position but on reaching the end of the array go back to the start and do the...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
2
by: liz0001 | last post by:
I am trying to run an SQL query for each item in an Array using ASP. I have coded it as such. IDsArray() is an array of integers. ArrayLength=15 sqlGetiIDs = "SELECT * FROM Table1 WHERE...
14
by: =?Utf-8?B?RWR3YXJk?= | last post by:
Hi everybody, To me the following code shouldn't work but it does ! Imports system.String Dim x As String="This,is,a,test" Dim y(1) As String y=x.Split(",") TextBox1.text=y(3) why "Y" which is...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.