First, let's define the number of CDs Phillip bought as #color(red)(C)# and the number of DVDs Phillip bought as #color(blue)(D)#.

We can now write a couple of equations.

First, the number number of items Phillip purchased can be written as:

#color(red)(C) + color(blue)(D) = 12#

The cost of the items Phillip purchased can be written as:

#$2color(red)(C) + $3color(blue)(D) = $31#

We can now solve the first equation for #color(red)(C)# or the number of CDs Phillip bought:

#color(red)(C) + color(blue)(D) - color(blue)(D) = 12 - color(blue)(D)#

#color(red)(C) + 0 = 12 - color(blue)(D)#

#color(red)(C) = 12 - color(blue)(D)#

Because we know what #color(red)(C)# equals we can substitute #12 - color(blue)(D)# for #color(red)(C)# in the second equation and solve for #color(blue)(D)# or the number of DVDs Phillip bought:

#($2 xx (color(red)(12 - color(blue)(D)))) + $3color(blue)(D) = $31#

#$24 - $2color(blue)(D) + $3color(blue)(D) = $31#

#$24 + (-$2 + $3)color(blue)(D) = $31#

#$24 + $1color(blue)(D) = $31#

#$24 + $1color(blue)(D) = $31#

#$24 - color(green)($24) + $1color(blue)(D) = $31 - color(green)($24)#

#0 + $1color(blue)(D) = $7#

#$1color(blue)(D) = $7#

#($1color(blue)(D))/($1) = ($7)/($1)#

#(cancel($1)color(blue)(D))/cancel(($1)) = (cancel($)7)/cancel(($1))#

#color(blue)(D) = 7#