jwk811 Posted February 20, 2007 Share Posted February 20, 2007 i forgot how to do this.. i return an array from a function, out can i get each part of that array out so i can use each value? Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/ Share on other sites More sharing options...
mbtaylor Posted February 20, 2007 Share Posted February 20, 2007 foreach ($array as $var => $value) { print ("$var = $value"); } // or print_r ($array); //or print ($array[0]); //or $max = count ($array); for ($i=0;$i<$max;$i++) { print ($array[$i]."<br />"); } Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/#findComment-189617 Share on other sites More sharing options...
utexas_pjm Posted February 20, 2007 Share Posted February 20, 2007 If the number of array elements are known you can use: http://us2.php.net/list Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/#findComment-189665 Share on other sites More sharing options...
.josh Posted February 20, 2007 Share Posted February 20, 2007 // or $x = 0; while ($array[$x]) { echo $array[$x]; $x++; } // or...LoL Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/#findComment-189667 Share on other sites More sharing options...
mbtaylor Posted February 20, 2007 Share Posted February 20, 2007 Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/#findComment-189668 Share on other sites More sharing options...
lando Posted February 20, 2007 Share Posted February 20, 2007 You could also use extract($array); There are some issues with using it but it is worth checking into because of its simplicity. http://www.php.net/manual/en/function.extract.php Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/#findComment-189681 Share on other sites More sharing options...
Barand Posted February 20, 2007 Share Posted February 20, 2007 // or $x = 0; while ($array[$x]) { echo $array[$x]; $x++; } // or...LoL CV, If error_reporting's "E_ALL" Your code is going to fall You should use "isset()" And then you won't get Annoying notices at all $x = 0; while (isset($array[$x])) { echo $array[$x]; $x++; } Quote Link to comment https://forums.phpfreaks.com/topic/39325-return-array/#findComment-189861 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.