Jump to content

Need advice storing variables


OM2

Recommended Posts

I need to store variables that look something like this:

 

3434432545 -> 32435219098999, title description 21

4455332545 -> 32411111118999, title description 22

9987432545 -> 32435211112999, title description 23

2111432545 -> 32222319098999, title description 24

 

I'm OK to have the above information hard coded

 

Answer: use an array?

 

I used to code in Perl (many years ago!!). There you had something called a hash table (I think!). Apparently, that was much better for doing a lookup. Is there something equivalent in PHP?

 

Also... it would be awesome if I could have something like this:

 

3434432545 -> 32435219098999, title description 21

4455332545 -> 32411111118999, 5657, title description 22

9987432545 -> 32435211112999, 32434, 2345, title description 23

2111432545 -> 32222319098999, 34243554, 43543, 453, title description 24

 

i.e. each object having potentially unlimited number of extra fields associated

 

Question: to start with, I'll have 100 - 200 of the above. But if I had 5000 say, how would this impact in loading into memory? Or is that too small and not something to worry about?

 

Thanks in advance!

 

 

OM

 

Link to comment
Share on other sites

You have data that you want stored. Apparently you have a key that then has defined, ie, named values related to it. Why are you not using a db table?

 

BTW - "...need advice storing variables..." - your title. Your data is not variables - it is data. What you are asking is how to store it. I suggest definitely not placing it in any variable until you first store it. And storing data is the preserve of databases.

 

You state that each object can have an unlimited number of extra fields.

Looking at:

3434432545 -> 32435219098999, title description 21

 

I'm assuming that 3434432545 is your 'object' and that the part following -> are two of the extra fields that are connected to that object. My question is - do you mean to say that the above object will have another pair of values like the ones above (but not the same value), or are you saying the data attached to this object is different, as in representing other info about this object? If the former, then you table structure could simply be "object_num,id_num,title" to represent the above, or it could be "object_num,id_num,title,someotherfield,somethirdfield,etc.,etc.,etc." as an object with several different attributes linked to it. AND - should you need multiple sets of these attributes, you simply create successive records using the same structure, with perhaps some counter, or sequence number to help uniquely identify each set of data belonging to a specific object number.

 

I hope I have made myself clear with my impression of your scenario and that you can adapt this to your personal vision.

Link to comment
Share on other sites

If you are "storing" this data, it should be in a database. You would want two tables. The first table would have fields for the values which each record would have only one value for. For the repeating data of a variable length, you would store those as separate records in another table that reference the parent record.

 

But, as far as working with the data in your code, an array makes sense. For the repeating data, I would create a sub-array. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.