php - preg match variable to not treat as a string -
$custom_sizes = array(); foreach (array('small', 'medium', 'large') $size) { if(preg_match('/size_{$size}/', $custom_sizes['size'])) { $price = $custom_sizes['price']; } }
the problem in here in if
condition, want obtain results like:
size_small, size_medium , size_large failed since treats whole string. how this?
use double-quotes.
but also, can alternation:
if( preg_match("/size_(?p<size>small|medium|large)/", $input, $match)) { $size = $match['size']; }
Comments
Post a Comment