• PHP Help PHP Newbies
  • form array Could anybody tell me what is wrong with this code <?php $ana =$_REQUEST['gram']; $anagram = explode (' ' , $ana); shuffle($anagram); foreach ($anagram as $anagrams) { echo &qu

<?php
$ana =$_REQUEST['gram'];
$anagram = explode (' ' , $ana);
shuffle($anagram);
foreach ($anagram as $anagrams)
{

echo "$anagrams";
}

?>

    You're exploding on spaces, that aren't there maybe?

      How does it not work?

      Oh, and try to use more descriptive yet less detailed topic headings.

        laserlight wrote:

        How does it not work?

        Oh, and try to use more descriptive yet less detailed topic headings.

        It explodes but does not shuffle. The form submits the data, the data is echoed but not shuffled. Any ideas?

          That's strange, try this:

          <?php
          $text = 'apple banana cheese dog elephant fish';
          $anagrams = explode (' ' , $text);
          shuffle($anagrams);
          foreach ($anagrams as $anagram)
          {
              echo $anagram . "<br />\n";
          }
          ?>

          If you happen to get the words in the original order, refresh the page (a few times if necessary, but that is unlikely to be needed). If you are using a version of PHP before 4.2, then also use [man]srand/man or [man]mt_srand/man, or simply upgrade.

            Write a Reply...