473,398 Members | 2,389 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,398 software developers and data experts.

sorting random values from a string

Hi
I have a php string like this:
$string = "one two three four five"
I have to sorting the values randomly every time the page are loaded.
So, for example:
first time
"one two three four five"
second time
"three five one four two"
third time
"five four two one three"
....
The number are a images in a folder and I have to sort these images in
a random sequence.
Thanks for suggestions.

Sep 6 '07 #1
7 3697
On Thu, 06 Sep 2007 15:39:06 +0200, pt36 <ke*********@gmail.comwrote:
Hi
I have a php string like this:
$string = "one two three four five"
I have to sorting the values randomly every time the page are loaded.
So, for example:
first time
"one two three four five"
second time
"three five one four two"
third time
"five four two one three"
...
The number are a images in a folder and I have to sort these images in
a random sequence.
Thanks for suggestions.

$string = "one two three four five";
$array = explode(' ', $string);
shuffle($array);
$string = implode(' ',$string);
--
Rik Wasmus
Sep 6 '07 #2
On Thu, 06 Sep 2007 15:47:51 +0200, Rik Wasmus
<lu************@hotmail.comwrote:
On Thu, 06 Sep 2007 15:39:06 +0200, pt36 <ke*********@gmail.comwrote:
>Hi
I have a php string like this:
$string = "one two three four five"
I have to sorting the values randomly every time the page are loaded.
So, for example:
first time
"one two three four five"
second time
"three five one four two"
third time
"five four two one three"
...
The number are a images in a folder and I have to sort these images in
a random sequence.
Thanks for suggestions.


$string = "one two three four five";
$array = explode(' ', $string);
shuffle($array);
$string = implode(' ',$string);
....ofcourse:
$string = implode(' ',$array);


--
Rik Wasmus
Sep 6 '07 #3
Ok Rik
thanks for your help, but please tell me why this work
<?php
$string = "uno.jpg due.jpg tre.gif quattro.gif cinque.jpg";
$array = explode(' ', $string);
shuffle($array);
$string = implode(' ', $array);
echo $string ;
?>

and this not work
<?php
if ($handle = opendir('banner/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file = $file . " ";
$array = explode(' ', $file);
shuffle($array);
$file = implode(' ', $array);
echo $file;
} }
closedir($handle);
}
?>

Sep 6 '07 #4
On Thu, 06 Sep 2007 17:26:25 +0200, pt36 <ke*********@gmail.comwrote:
Ok Rik
thanks for your help, but please tell me why this work
<?php
$string = "uno.jpg due.jpg tre.gif quattro.gif cinque.jpg";
$array = explode(' ', $string);
shuffle($array);
$string = implode(' ', $array);
echo $string ;
?>

and this not work
<?php
if ($handle = opendir('banner/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file = $file . " ";
Because a file might have a space in it, and it might be a directory? It's
quite nonsense to keep juggling between an array & a string.

<?php
if ($handle = opendir('banner/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if (is_file($file)) $files[] = $file;
}
shuffle($files);
echo implode(' ',$files);
closedir($handle);
}
?>
--
Rik Wasmus
Sep 6 '07 #5
Sorry Rik but this code not display nothing in my page
(in the directory banner I have some file)

<?php
if ($handle = opendir('banner/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if (is_file($file)) $files[] = $file;
}
shuffle($files);
echo implode(' ',$files);
closedir($handle);}

?>
I made mistake ?
Thanks
Sep 6 '07 #6
On Thu, 06 Sep 2007 18:12:40 +0200, pt36 <ke*********@gmail.comwrote:
Sorry Rik but this code not display nothing in my page
(in the directory banner I have some file)

<?php
if ($handle = opendir('banner/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if (is_file($file)) $files[] = $file;
}
shuffle($files);
echo implode(' ',$files);
closedir($handle);}

?>
I made mistake ?

Nope, I did :P

<?php
$dir = './banner';
if ($handle = opendir($dir)) {
$files = array();
while (false !== ($file = readdir($handle))) {
if (is_file($dir.'/'.$file)) $files[] = $file;
}
shuffle($files);
echo implode(' ',$files);
closedir($handle);}

?>
--
Rik Wasmus
Sep 6 '07 #7
Thanks Rik now work well
Have good day

Sep 6 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
16
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
7
by: Steve Bergman | last post by:
I'm involved in a discussion thread in which it has been stated that: """ Anything written in a language that is 20x slower (Perl, Python, PHP) than C/C++ should be instantly rejected by users...
11
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
1
by: dorandoran | last post by:
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. (I followed Satay's sample: http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx)...
4
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.