Store values in PHP -


I have an object on which there is a single comment and after that the object is sub -jected on which each comment on May be as it is today, I have comment on the whole object and a single variable to store a list for archiving comments for the object subject.

  public $ TestResultComments = array (); Public $ comment;  

Now I do not want to store plain text of only one comment but also to store the name of the person who wrote and timestamp. So instead of single variable $ comment , I now want to store three, what is the best way to store it, in the array or is there something similar, such as Haskell where there are tuples?

  $ comment = odbc_result ($ result, "comment"); $ UserName = odbc_result ($ result, "username"); $ TimeStamp = odbc_result ($ result, "timestamp"); $ TestResult-> Comment = $ comment; // I do this today, but I want to include $ username and timestamps here  

The second part is where I archive the subobjects for comments. ($ I = 1; $ i & lt; = $ no_results; $ i ++) for

{odbc_fetch_row ($ result, $ i); $ Type = trim (odbc_result ($ result, "result")); $ TestResult-> TestResultComments [$ type] = trim (odbc_result ($ result, "comment")); // Here I also want to store "comment", "username" and "timestamp" because they say in the database table and not only "comment" as I'm currently doing} < / Pre>

As you can see in the second example, I get an important value "result" to get the comment. Here I still want to get ("comment", "username", "timestamp") instead of a value.

Thanks in advance.

It seems that there is a good condition to use stdClass . stdClass allows you to dynamically declare fields for objects. key .

Example

 As  results  says,  $ allValues ​​= array (); // Create value $ value = new stud class (); $ Value- & gt; Comment = $ comment; $ Value- & gt; User name = $ username; $ Value- & gt; Timestamp = $ timestamp; $ Allvalues ​​[$ result] = $ value;  

This gives you several values ​​from a $ result direct mapping in a clean and OP method, in the future, let's say that you have the $ result < / Code>, you can say ..

  $ value = $ allvalues ​​[$ result]; The echo "username is" $ Values-> User name; I really like using it because it makes your code super clean and OF syntax, for loose typed languages ​​like POP, readability is sometimes lost, so It is important that you keep such behavior in order to keep things easy to understand. 


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -