Perfidus Posted October 11, 2007 Share Posted October 11, 2007 Hi there! I have a bunch of vars like tipo1, tipo2, tipo3, tipo4 sent via POST... The number may vary depending on user choice. I would like to recover the vars in an array, but the way I'm trying is not working: for($i=0;$i<$numberoftipos;$i++) { $tipo2=array($tipo[$i]); echo $tipo2[$i]."<br>"; } It echoes nothing... Any hints? Changing var names is not possible, I can't rename them like tipo[] because they come from multiple radio buttons, so they need differente names or only 1 will be able to be checked in a big list !!! Quote Link to comment Share on other sites More sharing options...
trq Posted October 11, 2007 Share Posted October 11, 2007 I would like to recover the vars in an array What does that meen? There already in an array, the $_POST array. Explain exactly what your trying to achive. Also, its easiest to loop through posted vars with a foreach(). eg; <?php foreach($_POST as $k => $v) { echo "$k = $v<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
Perfidus Posted October 11, 2007 Author Share Posted October 11, 2007 In the $_POST array there are too many vars, not only those who have the name tipo1, tipo2, tipo3, tipo4. Those are the ones >I want to recover inside an array called $tipo2 Quote Link to comment Share on other sites More sharing options...
coder_ Posted October 11, 2007 Share Posted October 11, 2007 You meen a recursiv function? Quote Link to comment Share on other sites More sharing options...
marcus Posted October 11, 2007 Share Posted October 11, 2007 Just rename them to tipo[] and give them individual values of 1, 2, 3 and 4. $tipo = $_POST['tipo']; if(count($tipo) > 0){ foreach($tipo AS $tipos){ echo $tipos . "<br>\n"; } } Quote Link to comment Share on other sites More sharing options...
Perfidus Posted October 11, 2007 Author Share Posted October 11, 2007 As I said, I can't rename them like tipo[] because they come from multiple radio buttons, so they need differente names or only 1 will be able to be checked in a big form !!! I'm sending lot's of vars using whatevername[] from the forms to automatically create the arrays, but with the radio buttons, I can't use the tipo[] name because then is impossible to check more than 1 option. Quote Link to comment Share on other sites More sharing options...
marcus Posted October 11, 2007 Share Posted October 11, 2007 Oops, guess I didn't catch that. Why don't you just do something like: for($i=1;$i<=4;$i++){ echo $_POST['tipo' . $i]; } Quote Link to comment Share on other sites More sharing options...
Perfidus Posted October 11, 2007 Author Share Posted October 11, 2007 gonna try, this is maybe what I was asking for... Quote Link to comment Share on other sites More sharing options...
Perfidus Posted October 11, 2007 Author Share Posted October 11, 2007 Well, it doesn't work, but it should be something like this... Just want to invoke them knowing that their names are composed by the word 'tipo' and a number... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.