dsnm64969 2016-08-06 23:19
浏览 43
已采纳

将键控数组转换为仅包含值的单维数组

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.....
  • 写回答

1条回答 默认 最新

  • dqxafj6830 2016-08-06 23:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法