I have this code:
<?php
if($row_s = ['prioridad'] == "normal") {
echo '<span class="badge badge-pill badge-cate-normal">Normal</span>';
} elseif($row_s = ['prioridad'] == "medio") {
echo '<span class="badge badge-pill badge-cate-medium">Medio</span>';
} else {
echo '<span class="badge badge-pill badge-cate-urgent">Urgente</span>';
}
?>
This model has 3 priorities, this is an example, the others are similar. What I'm trying to do is create a function in which I can call this function without having to repeat the code. I do not know how to do it. I don't know what I have to take into account because I don't understand them well.
function dato()
For example: I don't know what function fulfills data and I don't know if I have to add something inside the parentheses or not.
I hope you help me understand a little more php.
You can do this:
I put this example, first I have the variable that receives the data where the priority is specified
Second, I create a function where I receive the previous variable as an argument to process it inside
Inside the function through logical conditionals I check each of the 3 possible situations and at the end a default evaluation for when it is not any of the priorities
At the end I call the function in this way passing the variable as an argument
As this variable at the beginning was declared with the value of normal , the result once processed would be the following
In this way, the function by its name is the one that is invoked and only the variable that contains the priority to be evaluated is passed as an argument.