I have a string that looks something like this:
$string = "property1.property2.property3"
And I have an object, we'll call $object
. If I try to do $object.$string
it doesn't interpret it that I want property3
of property2
of property1
of $object
, it thinks I want $object."property1.property2.property3"
.
Obviously, using split('.')
is where I need to be looking, but I don't know how to do it if I have an unknown amount of properties. I can't statically do:
$split = $string.split('.')
$object.$split[0].$split[1].$split[2]
That doesn't work because I don't know how many properties are going to be in the string. So how do I stitch it together off of n
amounts of properties in the string?