I have an stdClass object that I have dynamically created from a JSON using json_decode(). I am trying to access a field by calling $value->V.X->processedField
but this field has a period. This is giving me a syntax error. Is there a way to somehow escape the period in my code, or am I going to have to rename the field in my JSON?
            Asked
            
        
        
            Active
            
        
            Viewed 73 times
        
    -3
            
            
         
    
    
        Caleb Collier
        
- 71
- 2
- 9
- 
                    Does this answer your question? [PHP regex periods](https://stackoverflow.com/questions/4012380/php-regex-periods) – Russ J Jun 10 '21 at 16:22
1 Answers
1
            <?php
// example code
$value = json_decode('{"V.X": {"processedField":"the value"}}');
print_r($value->{"V.X"}->processedField);
// or 
$var = "V.X";
print_r($value->$var->processedField);
 
    
    
        Kinglish
        
- 23,358
- 3
- 22
- 43
- 
                    3Some of these sort of questions have been asked repeatedly before, please try not to just answer without checking first. – Nigel Ren Jun 10 '21 at 16:42
- 
                    
- 
                    1It's a common thing, the idea is to just focus the answers to limit the repetition. – Nigel Ren Jun 10 '21 at 19:58