Jump to content


Photo

About percentage


  • Please log in to reply
7 replies to this topic

#1 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 30 October 2006 - 01:12 AM

Let's say I have this,
$type1 = '5'; // all the values are in %
$type2 = 15'';
$type3 = 20'';
$type4 = 50'';
$type5 = 10'';

Is it possible to assign them to
$type1_result = '11111';
$type2_result = '222222222222222';
$type3_result = '33333333333333333333';
$type4_result = '44444444444444444444444444444444444444444444444444';
$type5_resul = '5555555555';

Hope you understand what I'm trying to say..

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 October 2006 - 01:27 AM

Hope you understand what I'm trying to say..


Nope... sorry.

#3 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 30 October 2006 - 01:37 AM

Hmm ok, I will explain again..
If I put $A = 10;
Then I had another var, which is what I couldn't figure out myself.
Let's say that var is $A_Result, then I want the vaule of $A_Result to be AAAAAAAAAA. (There are 10's A)

So the value of $A_Result is depended on the value of $A.
Hmm.. Is this clear ?

To make it more clearer, this is the code I'm using now.
    function rtd($length)
{
	$dice1 = '5'; // Dice 1
	$dice2 = '15'; // Dice 2
	$dice3 = '20'; // Dice 3
	$dice4 = '50'; // Dice 4
	$dice5 = '10'; // Dice 5
	$dice6 = '0'; // Dice 6

	$chars = $dice1 . $dice2 . $dice3 . $dice4 . $dice5 . $dice6;
	for ($x = 1; $x <= $length; $x++)
	{
		$number = rand(1, strlen($chars));
		$dice .= substr($chars, $number - 1, 1);
 	}

 	return $dice;
}

Then when I echo out $dice, there's 5% will be Dice 1, 15% to be Dice 2, 20% to be Dice 3, 50% to be Dice 4, 10% to be Dice 5 and 0% to be Dice 6

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#4 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 30 October 2006 - 01:47 AM

for($count=0;$count<10;$count++)
{
        $result.=$a;
}


Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#5 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 30 October 2006 - 01:50 AM

<?php

for ($A = 1; $A <= 10; ++$A)  //Display 10 of the following
{
  echo 'A '; //10 What? 10 A's!
}
?>


#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 October 2006 - 01:50 AM

Still a bit lost. Something like....

<?php

  $a = 10;
  $a_result = 'a';
  echo str_pad($a_result,$a_result,$a);

?>

Maybe the question I should ask is why? What exactly are you trying to do?

#7 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 30 October 2006 - 01:52 AM

Just updated my previous post, hope it is clear enough.
Ok sorry, I got to work. I will read it again after I return home.

And thanks for all your helps.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#8 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 30 October 2006 - 03:32 PM

Ok, I'm back from work.
Hey fert, thanks for enlighten me.
I forgotten about the .
$result.=$a;

And thanks for all your helps again. Cheers :)

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users