reducing the size of this

He has: 296 posts

Joined: May 2002

Is there anyway to reduce the size of this file? I tried using for and foreach but it didn't work right.

test.php

I really hope there is a way, because 2 k for a file that does only that is to large in my opinion, and it'd probably be neater.

[James Logsdon]

He has: 1,016 posts

Joined: May 2002

Hmm.. I'm not sure exactly what you're trying to do, but the above could probably be done like this...

<?php


if ($do == 'more') {
 
$ep = $HTTP_COOKIE_VARS[\"EP\"];
 
$rand = rand(10,50);
 
$ep = $ep + $rand;
}

$EpNeed = array('0','156','390','780','1170','1560','1950','2340','2730','3120','3510','3900','4290','4680','5850','6240','6630','7020','7800','8190','8580'; // Currently goes to 20

if(
$ep <= 20) { // If you don't want the 20 limit, just raise or delete this if statement.
 
$level = $ep;
 
$next = $EpNeed[$ep] - $ep;
}
?>

He has: 296 posts

Joined: May 2002

I'll try that, but I don't think it will work. I'm writing a script for an RPG and the EP is for Experience Points, which is not the level. But I will try it anyway.

EDIT: Ya, that doesn't work at all. There might not be a way to make it smaller. I'll explain it (The script) more in a bit.

EDIT2: Click the link in my first post, I've explained what everything is/does.

[James Logsdon]

He has: 1,016 posts

Joined: May 2002

Ahhhh... Why didn't you say so from the begining. I wasn't sure what you wanted, try this code...

<?php


if ($do == 'more') {
 
$ep = $HTTP_COOKIE_VARS[\"EP\"];
 
$rand = rand(10,50);
 
$ep = $ep + $rand;
}

$EpNeed =  array('0','156','390','780','1170','1560','1950','2340','2730','3120','3510','3900','4290','4680','5850','6240','6630','7020','7800','8190','8580'); // Currently goes to 20

for(
$i = 0; $ep >= $EpNeed[$i]; $i++) {
$level = $i;
$next = $EpNeed[$i + 1];
}

setCookie(\"EP\",
$ep);

echo (\"<A HREF=\\"
test.php?do=more\\">Add EXP</A> Currently have $ep (Level $level)<BR />\");
echo (\"Next Level:
$next\");
?>

He has: 296 posts

Joined: May 2002

Awesome! I thought it would be for but I didn't know exactly how to do it. I learn something new every day Smiling Thanks Zollet!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.