clankill3r Posted October 30, 2011 Share Posted October 30, 2011 How can i get the content of the array? Or is the array empty? <?php include "../../../config.php"; include "../../../lib.php"; $words = $_POST['wordids']; print_r2($words); for($i = 0; $i < count($words); $i++) { echo "test"; $word = $words[i]; print_r2($word); } ?> Array ( [0] => Array [1] => Array [2] => Array [3] => Array [4] => Array ) test test test test test In case it helps, this is the form that sends the info: <?php include 'config.php'; include 'lib.php'; $db = dbConnect(); $words = getWords(); dbClose($db); ?> <html> <head> <title>Historer : Words</title> </head> <body> <? if(isset($_GET['removed'])) { ?><div id="message">Removed <? echo $_GET['removed'] ?></div> <? } ?> <div id="container"> <form method="post" action="inc/php/utils/word-exclude.php"> <input type='submit' name='submit' value='Exclude Selected Words'> <table> <tr> <td>word</td> </tr> <? foreach($words as $word) { ?> <tr> <td><input type="checkbox" name="wordids[]" value="<?=$word?>"><?=$word[word]?></td> </tr> <? } ?> </table> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/250098-get-content-of-array/ Share on other sites More sharing options...
AyKay47 Posted October 30, 2011 Share Posted October 30, 2011 use a foreach() loop to iterate through the values of the array Quote Link to comment https://forums.phpfreaks.com/topic/250098-get-content-of-array/#findComment-1283462 Share on other sites More sharing options...
clankill3r Posted October 30, 2011 Author Share Posted October 30, 2011 foreach($words as $word) { print_r2($word); } Array Array Array Array Array So those array's are empty right? Is it possible what i want? I use: <input type="checkbox" name="wordids[]" value="<?=$word?>"> where $word is like: $word[id] and $word[word], so 2 values. Quote Link to comment https://forums.phpfreaks.com/topic/250098-get-content-of-array/#findComment-1283471 Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2011 Share Posted October 30, 2011 You're dealing with a multidimensional array. What is the function print_r2()? Where is that defined? To see the structure of the array you're dealing with, print_r() the array within <pre></pre> tags. Quote Link to comment https://forums.phpfreaks.com/topic/250098-get-content-of-array/#findComment-1283479 Share on other sites More sharing options...
creata.physics Posted October 30, 2011 Share Posted October 30, 2011 foreach($words as $word) { print_r2($word); } Array Array Array Array Array So those array's are empty right? Is it possible what i want? I use: <input type="checkbox" name="wordids[]" value="<?=$word?>"> where $word is like: $word[id] and $word[word], so 2 values. Those arrays aren't empty. When it says array, you still have an array. For your code specifically, to display those arrays, you'd need to do: foreach( $words as $word ) { foreach ( $word as $_word ) { print_r2($_word); } } But, to actually determine what is what, in your loop that creates the input boxes, I'd set the array key to have the words id stored in it. $words = getwords(); foreach ( $words as $word ) { echo '<input type="checkbox" name="wordids['.$word['id'].']" value="'.$word.'">'; } Then, when you print_r($_POST['wordids'] ) You'll have a list of all your words, with the key and it's corresponding value. From there, you can loop the results and perform necessary queries. Quote Link to comment https://forums.phpfreaks.com/topic/250098-get-content-of-array/#findComment-1283501 Share on other sites More sharing options...
clankill3r Posted October 31, 2011 Author Share Posted October 31, 2011 cool thanks, that is what i wanted. Quote Link to comment https://forums.phpfreaks.com/topic/250098-get-content-of-array/#findComment-1283610 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.