473,671 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array and subarray

if I have
array-n-01=[0,1,2,3, 4,5, 6, 7,8,9,10]
array-n-02=[0,4,6,7]

want change in one array03 so:
array03[0]=[1.2.3]
array03[4]=[5]
array03[6]=[]
array03[7]=[8,9,10]

the sub elements in array03 are the
Aug 31 '06 #1
1 6066
artev wrote:
if I have
array-n-01=[0,1,2,3, 4,5, 6, 7,8,9,10]
The hyphen '-' is a punctuator in JavaScript and can't be used in an
identifier (such as a variable name). You might like to swap it for an
underscore. I think you mean that the numbers are actually the values
of the array elements, i.e.

var array_n_01 = [ '0,1,2,3', '4,5', '6', '7,8,9,10' ];

array-n-02=[0,4,6,7]
Will the order here *always* be the same as in array_n_01? If so, this
second array isn't needed. Otherwise, an example with it out of order
would have been better.

want change in one array03 so:
array03[0]=[1.2.3]
array03[4]=[5]
array03[6]=[]
array03[7]=[8,9,10]
Assuming the order is as per array_n_01:

var array_n_01 = ['0,1,2,3', '4,5', '6', '7,8,9,10'];
var array03 = [];

var x;
for (var i=0, len=array_n_01. length; i<len; i++){
x = array_n_01[i].split(',');
array03[x.shift()] = x.join(',');
}
Assuming the order is as per array_n_02:

var array_n_02 = [0,6,7,4];

for (var i=0, len=array_n_02. length; i<len; i++){
array03[array_n_02[i]] = [];
}
for (var p in array_n_01){
t = array_n_01[p].split(',');
array03[t.shift()] = t.join(',');
}
--
Rob

Sep 1 '06 #2

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

Similar topics

1
3800
by: Ante Perkovic | last post by:
Hi, everybody First, the code: --------------------- $maxNo = 500 $numbers = range (1,$maxNo); srand ((double)microtime()*1000000); shuffle ($numbers); $subarray = array_slice ($numbers, 0, 24); ksort ($subarray); // this also don't work!!!
5
2835
by: Frostillicus | last post by:
I'm trying to use array_multisort to sort by one of the dimensions of an array stored in $GLOBALS like this: array_multisort($GLOBALS, SORT_STRING, SORT_DESC); Each "row" in $GLOBALS contains a value for 'href', 'desc', and 'info' but when I try to pass one of these "columns" to array_multisort() it whinges about it not being an array or a sort value :-( Can PHP not understand arrays stored in $GLOBALS or something?
9
2613
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ 6.19 (http://www.eskimo.com/~scs/C-faq/q6.19.html). Thanks.
9
2310
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
2
14591
by: ron | last post by:
Hi, Could i clear the a single dimension array and a jagged array in the following way. int mySingleArr = new int; mySingleArr = System.Array.Clear(); int myJaggedArr = new int; myJaggedArr = new int;
1
8255
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a RankException. But the MSDN documentation says: When copying between multidimensional arrays, the array
4
23033
by: Sharon | last post by:
I’m using a one dimensional array: byte bArray = new byte; And I’m writing a function that return a subset of this array: void GetSubArray(int offset, int size, ref byte subArray); As you can see, the user asks for the bArray offset and size to put in the given subArray. How do I do that without copying the values? I want that the sub array will referee to the same memory/values as the bArray (same value)??? --
8
6104
by: Kresimir Spes | last post by:
Is the following C code possibile in C# (without the pointers ofcourse) int a; int* b=&a; // or a+100 b=0; what I would like to do is create a new int array object and have it point at the beginning of the 100th element of array "a" and set its size to 100 elements, so I can pass that reference array to another
2
1502
by: skavan | last post by:
Hi, Trying to wrap my head around the following problem. Let's say I have a 2 dimensional array: Dim arrS(3,4) As String I want to copy the subarray arrS(0,) to a new array arrLoop(4) As String.
0
8912
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7428
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.