3
For example,
amid my code I do
echo $num; //me retorna 1, mas se eu ecoar novamente a variável "$num"
//me retornará 2 e assim sucessivamente.
I tried a lot of different ways, but I couldn’t:
function add_um(){
}
add_um(); //Nesse caso toda vez que eu chamasse a função ela
//me traria um número diferente do anterior, sempre acrescentando 1 unidade.
I tried with while
, but fell into an infinite loop 1234567...
ADDED:
It is possible to use the $num
to name a session? type, $_SESSÃO[$num];
and then nominate another session hypothetically like this: $_SESSÃO[$num++];
?
That’s what I needed. Automatically naming sessions.
I thought of using the for
to create a $i
that would increase(i++
) each loop to name the sessions, but I’m already working within a for
and then the loops would keep repeating.
This number is fixed or passed as argument?
– rray
why not use increment http://answall.com/questions/15800/qual-a-difference%C3%A7a-entre-pr%C3%A9-e-p%C3%B3s-increment-in-javascript/15801#15801 in the answer is with javascript, but with php the logic is the same.
– Erlon Charles
Fixed. It would be the function itself.
– I Wanna Know
I know it’s with increment. I think I know... I just couldn’t build it. I’ll look at the link.
– I Wanna Know
SESSION-REF:
As chaves na $ _SESSION matriz associativa estão sujeitos às mesmas limitações que os nomes de variáveis regulares do PHP, ou seja, eles não podem começar com um número e deve começar com uma letra ou sublinhado.
What use do you want?– Papa Charlie
A simple
$_SESSION[]
would solve your problem? Creating an associative array starting with 0? http://sandbox.onlinephpfunctions.com/code/db6ab48e7989a0f8e4919ee5d30ab5b607da4ac7– gmsantos
@gmsantos added details to the question.
– I Wanna Know
I don’t know what that has to do with the original question but, if I understood correctly, just do $_SESSION[] = array() and store all the data you need in that array, and so the superglobal will behave in the most basic way it can be, that is, an array, incrementally and automatically increasing its indices.
– Bruno Augusto
It has to do with why I needed that knowledge to do it. But as through the answers I could not give continuity alone I’m putting more points.
– I Wanna Know
Sorry guy, I don’t mean to be rude, but you need to study a little more variables, arrays etc... go there in php manual and devour it a little, do tests with the manual examples out of your script, to understand how things work before trying to apply on something more complex. And what is that:
$i<$10
?– Jader A. Wagner
@Jader this was just a typo, I’ve corrected it. Well, you can tell the truth, man, I don’t resent it. I accept and agree and I try. I’ve been studying since morning. Before posting here I look in blogs, I watch video-lessons I read the manual, but the manual is very technical for those who are learning, it’s not like reading a history book that says so-and-so did it in such a year and ready you memorized/learned. When I talk here in the forum my mind opens. I am not only looking for ready codes and I am aware that no one has obligation to post them to me.
– I Wanna Know
@Jader But while I’m chasing, and I’ve already learned a lot for those who study "alone", I simply ask to see if I don’t get help. But yes I will study this and the other thousands of things I lack and always be you, I do not like falsehood. Thank you for everything you have posted.
– I Wanna Know
Please try not to ask a chameleon question (which changes from one thing to another). If you have new questions, ask new questions. I voted to close as "It is not clear what you are asking", because the question was quite confused...
– brasofilo
Completely changed the initial meaning of the question... the "echo ++" no longer fits... The issue has been resolved?
– Papa Charlie
From the point of view of the initial question it is solved. Should I remove what is not in the context of the initial question? I thought I could just sort things out.
– I Wanna Know
I confess that I lost myself with so much editing, so I asked... and also did not understand what functionality of what you are doing. I say this because there may be a simpler way to do it.
– Papa Charlie
@Iwannaknow, yes you can unroll things but through new questions, put a link to this one if it helps understand the new. The model of a Q&A site is completely different from that of a forum, check out the [tour] to learn more.
– brasofilo
Sure Brasófilo! I will pay more attention!
– I Wanna Know