How to shuffle an array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke noob
    New Member
    • Aug 2009
    • 69

    How to shuffle an array?

    Can anyone show me an example of how to shuffle an array?
    Last edited by Niheel; Oct 19 '10, 06:18 PM. Reason: Not needed
  • paulrajj
    New Member
    • Sep 2008
    • 47

    #2
    Hi,

    I think only this part is enough to get your answer.
    Code:
    foreach ($SwapLettersForSymbols as $letter => $Symbols) {
    	$wordFromForm1 = str_replace($letter,$Symbols,$wordFromForm);
    	echo $wordFromForm1 . "<br />"; 
    }

    Comment

    • luke noob
      New Member
      • Aug 2009
      • 69

      #3
      Thankyou, u were right i didnt need that part so i deleted it and made my script less confusing.

      [code=php]

      $Myarray("o" => "y",
      "o" => "z");

      foreach ($Myarray as $letter => $otherLetter) {
      $wordFromForm1 = str_replace($le tter,$otherLett er,$wordFromFor m);
      echo $wordFromForm1 . "<br />";
      }
      [/code]

      if i type in the letter "o" into my form i get....

      0
      z

      but i would like.....

      y
      z

      it always only prints the last letter but i want both, i cant understand whats happening here, any feedback would really help me out in the future please help.
      Last edited by luke noob; Oct 18 '10, 04:05 PM. Reason: typo :(

      Comment

      • luke noob
        New Member
        • Aug 2009
        • 69

        #4
        I think this is because im usin the same key value twice, so it takes the last one, is the only way round this to create a another separate array?

        Comment

        • paulrajj
          New Member
          • Sep 2008
          • 47

          #5
          Hi luke,

          You're right. Though you're trying to replace a character inside a loop, the character "o" is replaced to "z".

          Comment

          Working...