473,321 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

How to shuffle an array?

Can anyone show me an example of how to shuffle an array?
Oct 17 '10 #1
4 1683
Hi,

I think only this part is enough to get your answer.
Expand|Select|Wrap|Line Numbers
  1. foreach ($SwapLettersForSymbols as $letter => $Symbols) {
  2.     $wordFromForm1 = str_replace($letter,$Symbols,$wordFromForm);
  3.     echo $wordFromForm1 . "<br />"; 
  4. }
  5.  
Oct 18 '10 #2
Thankyou, u were right i didnt need that part so i deleted it and made my script less confusing.

Expand|Select|Wrap|Line Numbers
  1.  
  2. $Myarray("o" => "y",
  3.         "o" => "z");
  4.  
  5. foreach ($Myarray as $letter => $otherLetter) { 
  6.     $wordFromForm1 = str_replace($letter,$otherLetter,$wordFromForm); 
  7.     echo $wordFromForm1 . "<br />";  
  8.  
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.
Oct 18 '10 #3
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?
Oct 19 '10 #4
Hi luke,

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

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: JackM | last post by:
Let me attempt to explain my problem. I have a crude php script that takes a text list of songs that was generated by an mp3 list program and translates each entry into the form where they can be...
3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
1
by: Jim H | last post by:
I am on a project where I am supposed to send an XML document to a SQL Server stored procedure. The XML Doc is a list strings. If in my c# function I get a list values as (string psValueList),...
3
by: Jack Addington | last post by:
Quite new to C# but I am getting quite confused with Array's and ArrayLists. This is probably the same old iteration of a basic question but I can't seem to find a clear answer/example of this...
3
by: Terry Olsen | last post by:
I want to have an array of class objects that raise an event when a condition is true. Like so... ------------------------------------------------------- Public Class ClientHandler Public...
13
by: James | last post by:
Is this possible? I want to pass an array into a function that contains txtBox.Text properties... I was thinking something like this, but I know it won't work Dim vendorFields(9) As String ...
2
by: notaspdotnet | last post by:
I have a SQL table called "EXAMPLE" with 2 columns; personId and reportDate. personId consists of a 36 character GUID. reportDate has a date such as 1/1/2005, 2/1/2005,3/1/2005, etc. The date is...
3
by: krunk | last post by:
This is my code. I am to read in numbers from a file which is my nums.txt. Then we are to have the user choose what row or colum they would like to work with. I have two different functions for...
9
by: Tuxedo | last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any elements thereafter in an array in random order: var a = new...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.