You are here: Re: PHP Array Creation « PHP Programming Language « IT news, forums, messages
Re: PHP Array Creation

Posted by Oli Filth on 12/29/05 04:10

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] => smith@gmail.com
[varUserDateCreated] => 2005-12-15 15:17:41
)
...

should be:

[1] => Array
(
[varUserLoginName] => smith
[varUserPassword] => password
[varUserFullName] => Mr Smith
[varUserEmail] => smith@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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация