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.

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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历