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.
我有一个看起来像这样的字符串
$string = 'Name of product | 34';
我想把它分成两个新的字符串:
$productName = 'Name of product'; $productPrice = '34';
最好的方法是什么?
你可以很简单地使用list()and来做到这一点explode():
list()
explode()
list($productName, $productPrice) = explode(" | ", $string);
$productName string(15) "产品名称" $productPrice 字符串(2)“34”
$newarray = explode(" | ", $string); echo $newarray[0]; //Name of product echo $newarray[1]; //34