1

Good evening,

I have an array of 4 entries and each entry has 3 informations

1st entry:
field1 -> John
field2 -> 21
field3 -> 2020-06-05T19:58:53Z

2nd entry:
field1 -> Romeo
field2 -> 22
field3 -> 2020-06-05T19:48:00Z

3rd entry:
field1 -> Juliet
field2 -> 20
field3 -> 2020-06-05T18:38:10Z

4th entry:
field1 -> Mike
field2 -> 98
field3 -> 2020-06-05T19:22:22Z

Now, what I would like to achieve is to retrieve (browse) the respective value of the second field (namely 21, 22, 20, 98). Is there a smart way to achieve this or do I need to query each record?

I was planning to use :

foreach ($mystack as $value)
{
}

.. but maybe, I'm taking the wrong approach?

Please bear with me as I am a complete newbie with php :)

Many thanks for your help.

Laurent
  • 711
  • 2
  • 12
  • 30

1 Answers1

2

Use the array_column() function to extract all those values into an array.

foreach (array_column($mystack, 'field2') as $field2) {
    echo $field2 . "<br>";
}
Barmar
  • 741,623
  • 53
  • 500
  • 612