static variable - problem |
[eluser]penta997[/eluser]
I have a test function: Code: function test() and when I call this function, $x still equals 1, the static don't work. Please, help
[eluser]Cristian Gilè[/eluser]
Code: <?php The previous example keeps in memory the static variable and value is incremented. Every new controller instance removes the static variable from memory. Cristian Gilè
[eluser]penta997[/eluser]
Ok thanks. But what if my functon is more compicated, and when I call this function the data is adding to a sesstion for ex: Code: function addCards($id=1) How many times I must call this function in loop?
[eluser]Cristian Gilè[/eluser]
You can avoid static variables. If I haven't misunderstood what you are attempting to do, this is a possible solution: Code: function addCards($id=1) Cristian Gilè
[eluser]penta997[/eluser]
It's works. But tell me, please what means this line $suma = something ? something : 0.
[eluser]Cristian Gilè[/eluser]
It's the ternary operator. If the session suma is set, $suma gets session suma value otherwise 0. Cristian Gilè
[eluser]penta997[/eluser]
One more question How to set default value. Becouse if addCarts is not call, the value equals null, not zero but empty place.
[eluser]Cristian Gilè[/eluser]
Code: $this->session->set_userdata('suma', 0); You can set these sessions, for example, when the user is logged in. Cristian Gilè |
Welcome Guest, Not a member yet? Register Sign In |