0

I have to figure out how to present some data that is capture using gravity forms for wordpress.

There is a field for name, and attributes. Attributes contains a comma delineated list of values.

On a results page I need to display the names, followed by the top ten values. Where I'm stuck is is how to configure an array that gives me: distinct names, and within each distinct name is an array containing all values from the comma list(s).

I can't wrap my head around this to save my life. Given how GF stores enteries I think makes this especially difficult. Any guidance is much appreciated.

1 Answer 1

1
<?php
// A two-dimensional array:
$names = array
  (
  "sam"=>array(1,2,3,4,5,6,7,8,9,10),
  "joe"=>array(1,2,3,4,5,6,7,8,9,10),
  "bob"=>array(1,2,3,4,5,6,7,8,9,10)
  );
?>

Like that?

Sign up to request clarification or add additional context in comments.

6 Comments

Yes. You illustrate a good example that I need one big array to hold the distinct names then an array with each etc. What's the technical name of that and how could I push to that sub array of the distinct name? I'm decent at php but I'm getting lost in so many for each loops
That is called a 2 dimensional array.
Thanks for that. In a situation like this would I use array_push or do I explicitly state the values of the array? I guess where I'm lost is adding values to the sub array of a name. If I explicitly write values to a named array will that add it to that name or create an identically named array? Please forgive me if I'm not making sense its late :)
If you use the variable "names" then when you add to it, it should continue to add not create a new one. That is why we gave the array a label of "names".
I am not familiar with PHP but I just changed the Answer to give you better syntax, I hope. :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.