@switch - Switch Case Statement
The @switch directive in Ahmed PHP Template Engine allows you to execute different blocks of code based on the value of an expression, similar to a traditional switch statement in PHP.
Syntax
@switch(expression)
@case(value)
// Code to execute
@break
@case(value2)
// Another case
@break
@default
// Default case if no match is found
@endswitchExample
@switch($status)
@case('active')
<p>Status: Active</p>
@break
@case('pending')
<p>Status: Pending</p>
@break
@case('inactive')
<p>Status: Inactive</p>
@break
@default
<p>Status: Unknown</p>
@endswitchOutput (if $status = 'pending')
$status = 'pending')Notes
The
@casedirective is used to define each case.The
@breakdirective prevents fall-through behavior.The
@defaultdirective is optional and executes if no cases match.
Last updated