The while Statement

Oct 01, 2009 Author: Developer

For example, to use while to echo all of the values in $HTTP_POST_VARS, you can create a program like this:

<?php/*  prints contents of $HTTP_POST_VARS */?>
<title>Pela PHP Tutorials :: Example  :: What's in $HTTP_POST_VARS?</title>
// If count returns 0, there's nothing in the array
if ( count($HTTP_POST_VARS) < 1)
echo “There aren’t any elements in \$HTTP_POST_VARS.';
echo 'The following data is in \$HTTP_POST_VARS:<br>';
// Show the elements in the array one by onewhile ( list($key, $value) = each($HTTP_POST_VARS) )
echo '$key = $value<br>';
The count() function shown in this code is used to determine the number of elementsin an array. If 0 is returned, we can deduce that nothing was posted to the program,and it is unnecessary to try to show the elements in the array.

views 3863
  1. Add New Comment