Reputation: 24768
Let's say I have the following code
json_decode( $images_json );
json_decode( $cites_json );
But instead I want to use the input by a dynamic string, like this...
json_decode( {{$name}}_json );
...where $name
is a string containing "images
" or "cites
".
Is it possible? How?
Upvotes: 0
Views: 37
Reputation: 15550
Use this;
json_decode( ${$name . '_json'} );
You can refer here for further detail
Upvotes: 2
Reputation: 160853
You could do:
json_decode( ${$name.'_json'} );
But variable variables is not good idea usually, you may use an array to refactor your code.
Upvotes: 2