karen_west karen_west - 4 months ago 9
MySQL Question

Turned keyed array into single dimensional array with values only

I'm doing a PDO Query, using the

(PDO::FETCH_COLUMN, 0)
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.....

Answer

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.

<?php
$array = array("foo", "bar", "hello", "world");
var_dump($array);
?>

The above example will output:

array(4) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
  [2]=>
  string(5) "hello"
  [3]=>
  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.