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.
我有一个包含 2 个值的字符串:
$total = '100x100';
它也可以
$total = '10x10';
我想将这两个值相乘(100*100),同时消除“x”,这样我就可以让它说第一个值是“10000”,或者第二个值是“100”。
我已经消除了'x':
$total = str_replace('x', '', $total);
我现在可以做些什么来将两者相乘?
$values = explode('x',$total); array_product($values); // so even "10x40x20" is allowed and would work
将字符串分解成一个数组,然后将这两个数组项相乘,如下所示:
$total = array_product(explode('x', $string));
归功于 Shikiryu