Question

Is something like the following pseudocode possible in PHP?

$backing_type='work';

$work_token='123';
$review_token='456';   

echo ${$backing_type}_token;

//prints '123';
Était-ce utile?

La solution

Yes. You can do the following:

echo ${$backing_type . '_token'};

However, I would consider this messy programming. Using an array would be preferred:

$arr = array('work' => 123, 'review' => 456);
echo $arr[$backing_type];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top