2017-02-28 73 views
0

我已经将数据存储在像下面这样的单元格中: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($ row);

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

'$行[ 'RP1']'其实,有没有列'rp1',对不对? – RomanPerekhrest

+0

show'print_r($ row);' – JustOnUnderMillions

+0

@JustOnUnderMillions我得到这个:'Array([id] => 1 [dashboardId] => 1 [memberId] => 1 [rp1] => RP1 = 8 [rp2] = > RP2 = 6 [rp3] => RP3 = 8 [rp4] => RP4 = 7 [teamId] => 1)' – PhpDude

回答

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'];