473,378 Members | 1,175 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,378 software developers and data experts.

PHP Array Creation

Hey Guys
Lets assume we have two arrays
one bug array - main array
another user array - sub array

The bug array contains the id of the user to whom the bug is
assigned to.
This Id is present in the user array for example
bug - IE Error has assignedto id as 2
this id 2 corresponds to user Peter in the user array
how do i create a third array
bugUserArray such that
assigned to id of the bug user array should contain the complete
detail of particular user
as follows

-----------------------------------------------------------------
Bug Array
Array
(
[0] => Array
(
[varbugId] => 71
[varbugProjectId] => 23
[varbugAssignedToId] => 2
[varbugTitle] => IE Error
[varbugDescription] => The application ...
)

[1] => Array
(
[varbugId] => 72
[varbugProjectId] => 45
[varbugAssignedToId] => 3
[varbugTitle] => General Protection fault
[varbugDescription] => GPF Fault occurs ...
)

[2] => Array
(
[varbugId] => 73
[varbugProjectId] => 23
[varbugAssignedToId] => 2
[varbugTitle] => Login Problem
[varbugDescription] => User banned by the admin can...
)

)

-------------------------------------------------------
user Array
Array
(
[0] => Array
(
[varUserId] => 1
[varUserLoginName] => smith
[varUserPassword] => password
[varUserFullName] => Mr Smith
[varUserEmail] => sm***@gmail.com
[varUserDateCreated] => 2005-12-15 15:17:41
)

[1] => Array
(
[varUserId] => 2
[varUserLoginName] => Peter
[varUserPassword] => Peter
[varUserFullName] => Xavier Peter
[varUserEmail] => pe***@gmail.com
)

[2] => Array
(
[varUserId] => 3
[varUserLoginName] => coolguy
[varUserPassword] => password
[varUserFullName] => Administrator
[varUserEmail] => co*****@gmail.com
)

[3] => Array
(
[varUserId] => 4
[varUserLoginName] => alzemer
[varUserPassword] => alzemerlogin
[varUserFullName] => Alzemer Alex
[varUserEmail] => al*****@gmail.com
)
)

bug user array
-------------------------------------------------------------------
Bug User Array
Array
(
[0] => Array
(
[varbugId] => 71
[varbugProjectId] => 23
[varbugAssignedToId] => Array
(
[varUserId] => 2
[varUserLoginName] => Peter
[varUserPassword] => Peter
[varUserFullName] => Xavier Peter
[varUserEmail] => pe***@gmail.com
)
[varbugTitle] => IE Error
[varbugDescription] => The application ...
)

[1] => Array
(
[varbugId] => 72
[varbugProjectId] => 45
[varbugAssignedToId] => Array
(
[varUserId] => 4
[varUserLoginName] => alzemer
[varUserPassword] => alzemerlogin
[varUserFullName] => Alzemer Alex
[varUserEmail] => al*****@gmail.com
)
[varbugTitle] => General Protection fault
[varbugDescription] => GPF Fault occurs ...
)

[2] => Array
(
[varbugId] => 73
[varbugProjectId] => 23
[varbugAssignedToId] => Array
(
[varUserId] => 3
[varUserLoginName] => coolguy
[varUserPassword] => password
[varUserFullName] => Administrator
[varUserEmail] => co*****@gmail.com
)
[varbugTitle] => Login Problem
[varbugDescription] => User banned by the admin can...
)

)

Dec 28 '05 #1
2 1663
Prince of Code said the following on 28/12/2005 08:37:
Hey Guys
Lets assume we have two arrays
one bug array - main array
another user array - sub array

The bug array contains the id of the user to whom the bug is
assigned to.
This Id is present in the user array for example
bug - IE Error has assignedto id as 2
this id 2 corresponds to user Peter in the user array
how do i create a third array
bugUserArray such that
assigned to id of the bug user array should contain the complete
detail of particular user
as follows

<...SNIP ARRAY SAMPLE...>

Rather than storing the userID as a member of the array, why not use it
as the array key?

e.g.:

[0] => Array
(
[varUserId] => 1
[varUserLoginName] => smith
[varUserPassword] => password
[varUserFullName] => Mr Smith
[varUserEmail] => sm***@gmail.com
[varUserDateCreated] => 2005-12-15 15:17:41
)
...

should be:

[1] => Array
(
[varUserLoginName] => smith
[varUserPassword] => password
[varUserFullName] => Mr Smith
[varUserEmail] => sm***@gmail.com
[varUserDateCreated] => 2005-12-15 15:17:41
)

(Same principle could apply to the Bug Array.)

Then to create your Bug User Array, it's a trivial matter of getting the
relevant stuff out of the User array by key:

$BugUserArray[$x] = $BugArray[$x];
$BugUserArray[x]["varbugAssignedToId"]
= $UserArray[$BugArray[x]["varbugAssignedToId"]];
However, why would you want to replicate this much data? Why not just
keep everything in their respective arrays?

Also, this looks like a prime candidate for using a database - linking
data between tables is all handled automatically.
--
Oli
Dec 29 '05 #2
Following on from Oli Filth's message. . .
Prince of Code said the following on 28/12/2005 08:37:
Rather than storing the userID as a member of the array, why not use it
as the array key?

Because that's what PoC has been set to do as his coursework. He
frequently posts his assignments here expecting us to do them for him.

--
PETER FOX Not the same since the deckchair business folded
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Dec 29 '05 #3

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

Similar topics

3
by: mortoray | last post by:
Throughout the PHP manual, and normal code, one finds this construct: $var = array( ... ); However, as far as I can tell this is quite inefficient, since it always means two arrays are being...
6
by: Belmin | last post by:
I have an array. The array key is the id of the item (for example categories, 91 is the ID of the category) all ID are not exactly in date order, but they're added to the array in date order, how...
4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
1
by: None | last post by:
Dynamic array creation Hi all... here's a good one for you... I have a situation where I have some bean, and I need to populate an array field in it... here's the problem... I do not know the...
5
by: Manish | last post by:
This is the print_r() for a variable $categories. $categories :: Array ( =Array ( =Array (
5
by: David Golightly | last post by:
Quick question for the gurus out there: in ECMAScript, one can create a new Array object with a length like so: var animals = new Array(128); This creates a new Array object with a "length"...
14
by: Dan Rumney | last post by:
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = ; as opposed to using a constructor...
6
by: Cleber Schönhofen | last post by:
Hi, I need a dynamic array of objects, but don´t work. its work : DadosDoTime tt = new DadosDoTime; int i = 0; while (rd.Read()) { tt = new DadosDoTime(); tt.pos = 0;
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.