dongmaomou4117 2017-02-11 14:35
浏览 48
已采纳

将数字集合转换为数字

If I have a string as : 10 20 3 4 15 6

How can I convert it to individual numbers and store it in a array?

  • 写回答

2条回答 默认 最新

  • doumei9832 2017-02-11 14:49
    关注

    PHP is very clever when dealing with types of variables. You don't need it to be an integer, it can be a string of numbers, and PHP would still treat it as integers when performing operations on them.

    If you want to have each element be the numbers separated by spaces, you simply do

    $array = explode(" ", "10 20 3 4 15 6");
    

    The output of $array would then be

    Array ( 
        [0] => 10
        [1] => 20
        [2] => 3
        [3] => 4
        [4] => 15
        [6] => 6
    )
    

    Live demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教