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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -