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'); 8 1842
"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;
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 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 }
???
Sure, or to be very thorough, you could do:
if(is_array($myArray[0]['gallery'])) { //do gallery stuff }
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.
"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.
"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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |