karen_west karen_west - 2 months ago 4x
MySQL Question

Turned keyed array into single dimensional array with values only

I'm doing a PDO Query, using the

this returns the following result.

0 => string 'Sarah' (length=3)
1 => string 'Lisa' (length=3)
2 => string 'Katherine' (length=3)
3 => string 'Laura' (length=3)
4 => string 'Hannah' (length=3)
5 => string 'Becky' (length=3)
6 => string 'Stacey' (length=3)
7 => string 'Lauren' (length=3)

is there a php function to convert the array to values only, I'm looking for data similar to.

['Sarah', 'Lisa', 'Katherine', 'Laura', 'Hannah.....


As of PHP manual:

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

$array = array("foo", "bar", "hello", "world");

The above example will output:

array(4) {
  string(3) "foo"
  string(3) "bar"
  string(5) "hello"
  string(5) "world"

This actually means, that your example, i.e. ['Sarah', 'Lisa', 'Katherine', 'Laura', 'Hannah'], is actually this:

0 => Sarah
1 => Lisa
2 => Katherine
3 => Laura
4 => Hannah

How you display it on the page depends on you from that moment.