Conditionals in match_replace()
I would like to be able to specify conditionals in match_replace() strings. So, say I have a suffix I want to add to the string, but only if a value in the supplied data is TRUE
.
Example usage:
Say we want to replace a string that has a name, followed but an active indicator.
$users= [
[ 'name' => 'Joe Smith', 'active' => true ],
[ 'name' => 'Jane Boots', 'active' => false ]
];
foreach($users as $user)
echo match_replace('{{name}} {{?active:>(Active)}}', $users) . "\n";
This will output:
Joe Smith (Active)
Jane Boots
This will require two updates:
-
Output modifier >
that will cause the defined plain text to be output directly. -
The ?
check modifier that will test the defined value and only output if it evaluates TRUE.
Edited by Jamie Carl