RE: [PHP] Create Array??

2001-09-23 Thread Andrew Braund

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, 23 September 2001 15:39
 To: [EMAIL PROTECTED]
 Subject: [PHP] Create Array??
 
 
 Hi,
 
 If I have a value $num = 32; based on this how can I create an Array of 
 numbers 1 - 32, something like this...
 
 ?
 $num = 32;

 $num = 32;
 $iary = array();

 for ($i = 1; $i = $num; $i++)
 {

$iary[$i] = $i;
// if you actually wanted the array to contain 1 etc then try
// $iary[$i] = \$i\;

 // Do something
 }

// And now $iary = (1,2,3,etc

var_dump($iary);

 ?
 
 Any suggestions?? I cannot use array_push as this has to work on a PHP3 
 server.
 
 TIA
 Ade
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Create Array??

2001-09-23 Thread Evan Nemerson

/* Untested */
$num = 32;
$i=Array();
for($x=1;$x=$num;$x++) {
$temp[$x]=0;
};
$i=array_keys($temp);
unset($temp);


On Saturday 22 September 2001 23:09, you wrote:
 Hi,

 If I have a value $num = 32; based on this how can I create an Array of
 numbers 1 - 32, something like this...

 ?
 $num = 32;
 for ($i = 1; $i = $num; $i++)
 {
 // Do something
 }
 // And now $i = (1,2,3,etc
 ?

 Any suggestions?? I cannot use array_push as this has to work on a PHP3
 server.

 TIA
 Ade

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Create Array??

2001-09-23 Thread Evan Nemerson

$i=Array(); would probably be better as $temp=Array(); although i THINK 
either one is redundant...

sorry

 /* Untested */
 $num = 32;
 $i=Array();
 for($x=1;$x=$num;$x++) {
   $temp[$x]=0;
 };
 $i=array_keys($temp);
 unset($temp);

 On Saturday 22 September 2001 23:09, you wrote:
  Hi,
 
  If I have a value $num = 32; based on this how can I create an Array of
  numbers 1 - 32, something like this...
 
  ?
  $num = 32;
  for ($i = 1; $i = $num; $i++)
  {
  // Do something
  }
  // And now $i = (1,2,3,etc
  ?
 
  Any suggestions?? I cannot use array_push as this has to work on a PHP3
  server.
 
  TIA
  Ade

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Create Array?? More

2001-09-23 Thread KPortsmout

Ok, 

Thanks for the input, unfortunately it didn't help me solve my overall 
problem, so I will post that and see if anyone has any suggestions...

I am basically displaying the Usernames from a .htpasswd file like this...

$File=$Path$Directory1/.htpasswd;
$fd = fopen ($File, r);
$Content = fread ($fd, filesize ($File));
$Content=ereg_replace (\n,:, $Content);
// Explode the file using : as seperator
$MyContent = explode (:, $Content);
// Count it up
$LoU = count($MyContent)-1;
// Close the File
fclose($fd);

for ($a=0; $a  $LoU; $a+=2)
{
printf(\nTD%s/TD%sTD/TD, $MyContent[$a], $MyContent[$a+=2]);
}

This is working perfectly, but what I would like to do is display a number 
next to each one, at the moment it displays...

UserName1   UserName2
UserName3   UserName4

What I would like it to do is

1. UserName1   2. UserName2
3. UserName3   4. UserName4

I cannot figure a way to use $a because it has to skip by 2 in order not to 
display the encrypted passwords..any suggestions???

TIA
Ade

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Create Array??

2001-09-23 Thread Alexander Skwar

So sprach »[EMAIL PROTECTED]« am 2001-09-23 um 02:09:17 -0400 :
 Hi,
 
 If I have a value $num = 32; based on this how can I create an Array of 
 numbers 1 - 32, something like this...
 
 ?
 $num = 32;
$arr = array();
 for ($i = 1; $i = $num; $i++)

$arr[] = $i;

Alexander Skwar
-- 
How to quote:   http://learn.to/quote (german) http://quote.6x.to (english)
Homepage:   http://www.digitalprojects.com   |   http://www.iso-top.de
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 3 days 19 hours 40 minutes

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Create Array?? More

2001-09-23 Thread Andrew Braund

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, 23 September 2001 16:46
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Re: [PHP] Create Array?? More
 
 
 Ok, 
 
 Thanks for the input, unfortunately it didn't help me solve my overall 
 problem, so I will post that and see if anyone has any suggestions...
 
 I am basically displaying the Usernames from a .htpasswd file like this...
 
 $File=$Path$Directory1/.htpasswd;
 $fd = fopen ($File, r);
 $Content = fread ($fd, filesize ($File));
 $Content=ereg_replace (\n,:, $Content);
 // Explode the file using : as seperator
 $MyContent = explode (:, $Content);
 // Count it up
 $LoU = count($MyContent)-1;
 // Close the File
 fclose($fd);
 
 for ($a=0; $a  $LoU; $a+=2)
 {
 printf(\nTD%s/TD%sTD/TD, $MyContent[$a], $MyContent[$a+=2]);
 }
 
 This is working perfectly, 

perhaps not for odd numbers of users?

Try; (untested!)

echo tr\n;
for ($i=0; $i*2  $LoU; $i++){
   printf(td%d./tdtd%s/TD, $i, $MyContent[$i*2]);
   if( $i % 2){ // new line after each two entries
echo /trtr\n;
   }
}
echo /tr\n;


but what I would like to do is display a number 
 next to each one, at the moment it displays...
 
 UserName1   UserName2
 UserName3   UserName4
 
 What I would like it to do is
 
 1. UserName1   2. UserName2
 3. UserName3   4. UserName4
 
 I cannot figure a way to use $a because it has to skip by 2 in order not to 
 display the encrypted passwords..any suggestions???
 
 TIA
 Ade


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] create array of random unique integers?

2001-02-18 Thread Robin Vickery


 "a" == andrew  [EMAIL PROTECTED] writes:

  Hi, is there a quick way to create an array of integers, randomized
  and without repeats?

  e.g. if my set is 1 - 10, create an array whoese key values are 1
  through 10, with corresponding key values as a random set of the
  same 1 through 10??

  thanks in advance for any suggestions :) andrew

Yeah, this will give you an array of the numbers 1 - 10 in random
order. If you want a different range, change the parameters to suit.

?php
function rand_array( $start, $finish ) {
  srand ( (double) microtime() * 100);
  $rand_array = range( $start, $finish );
  // it really irritates me the way PHP's sort functions mess around
  // with the original array rather than returning a sorted array so
  // I can assign it to where I want it.
  shuffle( $rand_array ); 
  return $rand_array;
}

print_r( rand_array(1, 10) );

?



-- 
Robin Vickery.
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]