-3

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?

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 Answers1

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