从数据库选择中删除字符串中的特定字符

时间:2017-02-28 10:22:31

标签: php

我已将数据存储在以下单元格中:RP1=8, RP2=6, RP3=8, RP4=7当我调用该数据去除RP1=部分时只留下值?

$row = $result->fetch_assoc();
echo $row['rp1'];
echo $row['rp2'];
echo $row['rp3'];
echo $row['rp4'];

的print_r($行);

Array ( [id] => 1 [dashboardId] => 1 [memberId] => 1 [rp1] => RP1=8 [rp2] => RP2=6 [rp3] => RP3=8 [rp4] => RP4=7 [teamId] => 1 )

1 个答案:

答案 0 :(得分:1)

罗马的一种方式:

$row = $result->fetch_assoc();
#replace can go over all entries here, it is specific enuff
$row = array_map(function($a){return preg_replace('#^(RP[0-9]+=)#','',trim($a));},$row);
echo $row['rp1'];
echo $row['rp2'];
echo $row['rp3'];
echo $row['rp4'];