将给定的字符串拆分为两个变量

将给定的字符串拆分为两个变量

本文介绍了将给定的字符串拆分为两个变量-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了变量$ pos,它在一个String中包含两个数字:

I got the variable $pos, which contains two numbers in one String:

$pos = 98.9 100.2

如何将其分为2个变量?我显然必须检查一下两者之间的空间.之后我想有两个变量:

How can I split this into 2variables? I oubviously have to check for the space in between.I would like to have two varibles afterwards:

$number1 = 98.9
$number2 = 100.2

推荐答案

list($number1, $number2) = explode(' ', $pos);

但是,在执行此操作之前,请确保字符串具有正确的格式.

However, make sure the string has the right format before doing this.

这篇关于将给定的字符串拆分为两个变量-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 11:05