473,563 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 multidimensiona l 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('fundrai se'=>'Fundraise ');
$links[6]=array('events' =>'Events');
$links[7]=array('contact '=>'Contact');
///// GALLERY LIST /////
$gallery[0]=array('service '=>'Service','r eception'=>'Rec eption');
$gallery[3]=array('family' =>'Family','chi ldren'=>'Childr en','adults'=>' Adult
s');
$gallery[5]=array('cards'= >'Cards','leafl ets'=>'Leaflets ');



Aug 12 '05 #1
8 1871

"PhilM" <ph***@nospam.c om.am> wrote in message
news:42******** **************@ news.optusnet.c om.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('fundrai se'=>'Fundraise ');
$links[6]=array('events' =>'Events');
$links[7]=array('contact '=>'Contact');
///// GALLERY LIST /////
$gallery[0]=array('service '=>'Service','r eception'=>'Rec eption');
$gallery[3]=array('family' =>'Family','chi ldren'=>'Childr en','adults'=>' Adult s');
$gallery[5]=array('cards'= >'Cards','leafl ets'=>'Leaflets ');

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

$indexer=0;
foreach (array_keys($li nks) as $linkKey){
$collecter[$indexer]=$linkKey;
$indexer++;
}
foreach (array_keys($co llecter) as $linkKey){
if ($links[$collecter[$linkKey]]){
$linksHolder[$linkKey]=$links[$collecter[$linkKey]];}
if ($gallery[$collecter[$linkKey]]){
$galleryHolder[$linkKey]=$gallery[$collecter[$linkKey]];}
}
$links=$linksHo lder;$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('fundrais e'=>'Fundraise' );
$myArray[6]['links'] = array('events'= >'Events');
$myArray[7]['links'] = array('contact' =>'Contact');
///// GALLERY LIST /////
$myArray[0]['gallery'] =
array('service' =>'Service','re ception'=>'Rece ption');
$myArray[3]['gallery'] =
array('family'= >'Family','chil dren'=>'Childre n','adults'=>'A dult
s');
$myArray[5]['gallery'] =
array('cards'=> 'Cards','leafle ts'=>'Leaflets' );

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

$myArray = array_merge($my Array); //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('fundrais e'=>'Fundraise' );
$myArray[6]['links'] = array('events'= >'Events');
$myArray[7]['links'] = array('contact' =>'Contact');
///// GALLERY LIST /////
$myArray[0]['gallery'] =
array('service' =>'Service','re ception'=>'Rece ption');
$myArray[3]['gallery'] =
array('family'= >'Family','chil dren'=>'Childre n','adults'=>'A dult
s');
$myArray[5]['gallery'] =
array('cards'=> 'Cards','leafle ts'=>'Leaflets' );

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

$myArray = array_merge($my Array); //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($my Array[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********@gma il.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Sure, or to be very thorough, you could do:

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


thx again.
Aug 13 '05 #7
"Chung Leong" <ch***********@ hotmail.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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.a u>, 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('fundrai se'=>'Fundraise ');
$links[6]=array('events' =>'Events');
$links[7]=array('contact '=>'Contact');
///// GALLERY LIST /////
$gallery[0]=array('service '=>'Service','r eception'=>'Rec eption');
$gallery[3]=array('family' =>'Family','chi ldren'=>'Childr en','adults'=>' Adult
s');
$gallery[5]=array('cards'= >'Cards','leafl ets'=>'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
1826
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 http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/array.html#1194827 but there was no mention of particular constructors having to be used. And if so how does one...
38
5166
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 let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of...
22
1790
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 systems analysis.
8
10701
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 receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type...
21
3179
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a...
3
1699
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 rest so that on ever loop every element is checked in the right order. For example int totalCount=0; //to internally track total elements parsed
272
13946
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 dimensional arrays from std::vectors ??? I want to use normal Array Syntax.
2
2873
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 (dID = " & IDsArray(j) & ")" j=0 Dim GetiIDsRSArray(ArrayLength)
14
990
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 an array of lenght 2 accepts index 3 which is larger than its lenght? Any thoughts?
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.