Jump to content


Photo

help


  • Please log in to reply
2 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 15 August 2006 - 08:54 AM

<?php

$a = RAND(1,1000);

$numbers=array('1','2','3','4','5','6','7','8','9','0');

$images=array('<img src="1.gif">','<img src="2.gif">','<img src="3.gif">','<img src="4.gif">','<img src="5.gif">','<img src="6.gif">','<img src="7.gif">','<img src="8.gif">','<img src="9.gif">','<img src="0.gif">');

$b=str_replace($numbers,$images,$a);

echo $b;

?>

i have the above code which outputs one result for $a... but is there away to turn this into a function so say i have like 5 different numbers...

$f = "555";
$e = "43545";
$g = "45453";
$h = "34553";
$m = "34535";

it would do the above to all of them and not just $a..

any help would be appreciated..

thanks


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 15 August 2006 - 09:53 AM

function num_swap ($val)
{
$numbers=array('1','2','3','4','5','6','7','8','9','0');

$images=array('<img src="1.gif">','<img src="2.gif">','<img src="3.gif">','<img src="4.gif">','<img src="5.gif">','<img src="6.gif">','<img src="7.gif">','<img src="8.gif">','<img src="9.gif">','<img src="0.gif">');

$b=str_replace($numbers,$images,$val);

echo $b;
}

num_swap('555');
num_swap('43545');

and so on......
follow me on twitter @PHPsycho

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 15 August 2006 - 10:28 AM

awesome. exactly wat i wanted. thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users