Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从 PHP 中的一个字符串创建两个变量。
例如
$string = "2,50";
至
$a = "2"; $b = "50";
怎么做?
我想<sup>在价格上使用它的美分并以不同的方式设计它,但我有这个数字作为一个整体。所以我需要把它分成两个pireses。
<sup>
字符串的格式总是有两个小数点和一个逗号作为分隔符,这应该有点帮助。
知道如何使用 PHP 做到这一点吗?
重要的!我需要在 PHP 中不使用数组来做到这一点!
您可以使用该list构造explode()来实现此目的:
list
explode()
list($a, $b) = explode(',', trim($string));
演示。
使用preg_split()这将为您提供一个包含两个条目的数组,将这些条目的值添加到您的原始变量中。