$string = "706AN=0,503-PP=0,504-PP=0,519=0,606BOX=0,417=2";
//此变量是数据库列类型文本的结果
我需要在“=”之前单独获取代码,并在“=”之后分配给该代码的结果。拆分字符串应该返回类似于:
的内容Code 706AN has quantity 0
Code 503-PP has quantity 0
Code 504-PP has quantity 0
Code 519 has quantity 0
Code 606BOX has quantity 0
Code 417 has quantity 2
如何使用自己的数量结果减去每个代码?
答案 0 :(得分:2)
你可以使用explode
$string = "706AN=0,503-PP=0,504-PP=0,519=0,606BOX=0,417=2";
$temp = explode(',', $string);
foreach ($temp as $key => $value) {
list($code,$quantity) = explode('=', $value);
echo "Code $code has quantity $quantity </br>";
}
答案 1 :(得分:1)
$string = "706AN=0,503-PP=0,504-PP=0,519=0,606BOX=0,417=2";
$exp = explode(',', $string);
foreach ($exp as $key => $value) {
$list = explode('=', $value);
echo "Code $list[0] has quantity $list[1] </br>";
}
答案 2 :(得分:-1)
我可以稍后给你一个代码示例,我很着急atm
HTH