dongtan1009 2011-03-01 11:19
浏览 20
已采纳

我如何得到<246.64260,167.12500,24.62500>来分隔变量?

if i have <246.64260, 167.12500, 24.62500> each number can be from 1 to 256. I need to get it in to $X as 246, $Y as 167 and $Z as 24

How would i do this? I was thinking to remove all the spaces and them explode to get

X 246.64260
Y 167.12500
Z 24.62500

then explode again to get X 246 Y 167 Z 24

Is this the best way of doing this?

  • 写回答

5条回答 默认 最新

  • dongtiao1817 2011-03-01 12:01
    关注

    I'm going to blow your mind and do it really easily in one line (two if you count the string):

    $str = '<246.64260, 167.12500, 24.62500>';
    list( $X, $Y, $Z ) = array_map( 'intval', explode( ',', trim( $str, '<>' ) ) );
    

    This will trim off the leading GT and LT characters, then explode the numbers into an array using the commas. Leading whitespace (surprisingly) doesn't matter with intval so it is simply mapped to the separated array and then the results are separated into the $X, $Y, and $Z variables you asked for.

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

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输