0

I have stored data in cells like the following: RP1=8, RP2=6, RP3=8, RP4=7 is there a ways that when I call that data to strip out the RP1= portion just leaving the value?

$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 )
8
  • $row['rp1'] actually, there's no column rp1 , right? Commented Feb 28, 2017 at 10:24
  • show print_r($row); Commented Feb 28, 2017 at 10:25
  • @JustOnUnderMillions I get this: Array ( [id] => 1 [dashboardId] => 1 [memberId] => 1 [rp1] => RP1=8 [rp2] => RP2=6 [rp3] => RP3=8 [rp4] => RP4=7 [teamId] => 1 ) Commented Feb 28, 2017 at 10:26
  • 1
    You should clean-up your values in the database itself; remove the column names from them. Commented Feb 28, 2017 at 10:27
  • 1
    Do this print preg_replace('#(RP[0-9]+=)#','','RP8=2'); like print preg_replace('#(RP[0-9]+=)#','',$row['rp1']); Commented Feb 28, 2017 at 10:44

1 Answer 1

1

One way to rome:

$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'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.