3
I would like to know how to return the variable of larger number but not the value and yes which is larger.
For example:
$valor_01 = 6;
$valor_02 = 4;
$valor_03 = 3;
$valor_04 = 9;
$valor_05 = 8;
$valor_06 = 5;
echo max($valor_01, $valor_02, $valor_03, $valor_04, $valor_05, $valor_06);
// OUTPUT EXIBIDO
// 9
// OUTPUT DESEJADO PARA CONTROLE
// VAR $valor_04
I will use this variable for controls if
, but I need to know which is the largest variable and not the value.
If anyone knows how to ride even otherwise, thank you.
explain better the need to know the variable name
– Pedro Laini
Your problem probably already starts by using several variables instead of one array. Learn to use the right resource and you won’t have to deal with it. You get nothing by doing it, not even learning.
– Maniero
Moisesgame, I gave you the answer you need. That’s what you asked. But depending on what you need to do in your application, you can use another method. In that case you could explain to us what you need and we can give you alternatives. I learned from this question, even if out of curiosity, how to print the name of a variable. Will I use a day? I don’t know. But it’s good to know. And surely you get learning too.
– Diego Souza
@Pedrolaini I want the return of the larger variable and not the value. If the variable
$valor_04
is the biggest. I want to use it later on aif
for exampleif ($variavel_maior > $variavel_atual)
. I tried to be clearer =]– MoisesGama
Moises, by your answer of now, it is possible for you to do otherwise what you want, other than by that way which is not the most recommended.
– Diego Souza
@Diegosouza how could I do? I’m doing so because these values come from queries in the bank, one of each different query. If you could help me, I’d really appreciate it.
– MoisesGama
How these values come from the database ?
– Diego Souza
@Diegosouza There are 6 separate queries, each of a date. Each query returns 2 different values that are summed into a variable. An example
$total_data_01 = ( round( $dados_data_01["LIGACOES"] * 0.7 ) + round( $dados_data_01["CONTATOS"] * 0.8 ) );
– MoisesGama
@Diegosouza so use in variables, I have to treat their values later.
– MoisesGama
@Moisesgama the only correct solutions to your problem is Pedro Laini and Daniel Gregatto. Learn to do it the right way. If there is something he can improve on, put a comment in his answer, but don’t adopt wrong solutions. Although they could be simplified.
– Maniero
@Moisesgama I answered your question for the purpose you need, but in case of collections or sequences, I recommend using array, not only for the use of memory, but for the advantage of organization and understanding of the code.
– Ivan Ferrer
@Ivanferrer Your response has met your needs. Thank you very much! You commented to use
array
how his response could adapt into aarray
, could you make an example in your reply? Thank you.– MoisesGama