3
I have the following array,
$status = array();
$status["Visualizar"] = "Visualizar";
$status["Editar"] = "Editar";
$status["Status"] = "Alterar Status";
$status["Boleto"] = "Gerar Boleto";
It turns out that depending on the current status going from 1 to 10 I must or must not show the Item $status["Status"], well with the if resolves, but it turns out that when I give an unset and then reinsert the item it goes to the end of the list, but I need it to be in the original position before billet
Example:
if ($codstatus == 3){
$status["Status"] = "Alterar Status";
}else{
unset($status["Status"]);
}
Has an elegant way of doing this or I’ll have to redo the entire array every time?
I don’t understand why you need the position if the key to your matrix is a text
– user3603
It is a text because in a foreach I list this array in a combo for the user to choose, so should keep the position
– Marcelo
I don’t consider this a legal code but it might help you: https://repl.it/Gudr/2 I suggest you use only integers to index your array, so you can set the position where you want to insert your text.
– user3603
Sometimes we need to use by name in the keys to facilitate reading in other parts of the code, there is a very large system interaction with javascript so I need the keys with names and not numbers, which would be impossible to remember what each number represents. I’m studying the array_splice tip
– Marcelo
There is no mystery, just check in javascript if the key exists
– Papa Charlie