I have a function which must return one dimensional associate array, like $user_info[$index]=value where $index is a string which consist of
- user_id
- full_name
- photo_file_name
for example, my associative array could look like $user_info['user-123456789~~Bill Gates~~bill_gates.png']=$value. I need user_id, full_name and photo for another needs, in order to know whose value is this and what is his full name, etc.
So, the questions that has risen are following:
- Is it OK to have such an array if to take into account performance of the application?
- If it is bad (I think that it is bad idea) so how can I solve my problem in this case.
Additional info. This function retrieves user information into this associative array and returns this array. Further, my application stores it in a session in order to address it and retrieve information right from the session variable, not execute once again a query. And finally the reason I need one dimensional array is that I use a function array_diff where one of the arrays are $user_info array.
Note, Take into account that one user could have 1 or many values.
Any suggestions would be pleased.
You have a long key in an associative array.
I don’t think it’s a problem. If you wanted to shorten it you could hash your key-value and store the value with the hashed value.
That being said, have you asked yourself why you’re using that schema? Might it be better to come up with a different data structure to suit your needs?
I’d be much more concerned with the amount of data (size of the array) that you’re storing in the session variable. I think using the session to store data like this is a bad idea.