Jump to content

Php math


cry of war

Recommended Posts

how would i add the numerical of several different arrayed variables only chooseing the ones i want  and set them to equal like $somenumber for example $somenumber = $info[1] + $info[37] + $info[34] + $info[12] + $info[88] 

 

all $info[x] are equal to somenumber

Link to comment
Share on other sites

$armynouu is what im trying to get and this is what the user is inputting into the text area

 

recon Mission Report

Under the cover of night, your 1,000,000 Covert Ops sneak into the realm of overburnit .

Your Covert Ops move stealthily through the lands of overburnit undetected. They are able to gather many documents recording the status of weapons, army size and preparedness, and fortifications. Unfortunately, in order to avoid detection, they are not able to provide complete information. Your Chief of Intelligence provides you with the information gathered:

 

 

Army Size:

Unit Type

Attackers Defenders Untrained

 

bot 0 0  0 

Units 0  0  7227 

Human Form Units 100000  930000  1478941 

 

 

Military Stats

Strike Action: 0 

Defensive Action ??? 

Covert Action: 60,353,919,808 

AntiCovert Action 0 

Covert Skill: 22 

Covert Operatives: 1050000 

 

Anti-Covert Skill: 21 

Anti-Covert Operatives: 0 

Attack Turns: 633 

Unit Production: 4544

 

 

 

 

<?php
// if page is not submitted to itself echo the form
if (!isset($_POST['submit']))
{
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
PLEASE CLICK INSIDE OF THE SGW SPY LOG AREA AND PRESS CTRL+A THEN CTRL+C THEN CLICK IN THE
TEXT AREA BELOW WHERE IT SAYS "INSERT HERE".
<textarea rows="20" cols="20" name="info" wrap="physical">INSERT HERE</textarea><br />
ENTER ID: <INPUT TYPE="TEXT" name="id" value="INPUT ID HERE" /><br />
<input type="submit" value="submit" name="submit" />
</form>

<?PHP
}
else
{
   $info = $_POST['info'];
   $id   = $_POST['id'];
$find = array('bot', 'Units', 'Human Form troop2a', 'Mercenaries', 'Jaffa Army', 'Super Soldiers', 'Mercenaries', 'Soldier', 'NID Agent', 'Mercenaries', 'Drones', 'Clones', '  ', ','); 
$replace = array('troop1a', 'troop2a', 'troop3a', 'troop1b', 'troop2b', 'troop3b', 'troop1c', 'troop2c', 'troop3c', 'troop1d', 'troop2d', 'troop3d', ' ', '');
$info = str_replace($find, $replace, $info);
   $info2 = explode(" ", $info);
$armynouu = ($info[79] + $info[80] + $info[81] + $info[83] + $info[84] + $info[87] + $info[88] + $info[89] + $info[109] + $info[115]);
echo "<pre><a href=http://www.stargatewars.com/stats.php?id=$id target=_blank>$race $info2[16] $race ($armynouu ~ $info2[121]</a><br /></pre>";
   for($i = 0; $i <= 200; $i++)
   {
    echo "Piece $i = $info2[$i] <br />";
   }
}
?>

Link to comment
Share on other sites

try

<?php
$info = 'recon Mission Report
Under the cover of night, your 1,000,000 Covert Ops sneak into the realm of overburnit .
Your Covert Ops move stealthily through the lands of overburnit undetected. They are able to gather many documents recording the status of weapons, army size and preparedness, and fortifications. Unfortunately, in order to avoid detection, they are not able to provide complete information. Your Chief of Intelligence provides you with the information gathered:


Army Size:
Unit Type
Attackers Defenders Untrained

bot 0 0  0 
Units 0  0  7227 
Human Form Units 100000  930000  1478941 


Military Stats
Strike Action: 0 
Defensive Action Huh 
Covert Action: 60,353,919,808 
AntiCovert Action 0 
Covert Skill: 22 
Covert Operatives: 1050000 

Anti-Covert Skill: 21 
Anti-Covert Operatives: 0 
Attack Turns: 633 
Unit Production: 4544';
$find = array('bot', 'Units', 'Human Form troop2a', 'Mercenaries', 'Jaffa Army', 'Super Soldiers', 'Mercenaries', 'Soldier', 'NID Agent', 'Mercenaries', 'Drones', 'Clones', '  ', ','); 
$replace = array('troop1a', 'troop2a', 'troop3a', 'troop1b', 'troop2b', 'troop3b', 'troop1c', 'troop2c', 'troop3c', 'troop1d', 'troop2d', 'troop3d', ' ', '');
$info = str_replace($find, $replace, $info);
preg_match_all('/.+ [0-9]+/', $info, $a);
foreach ($a[0] as $k => $v) {
preg_match_all('/([^0-9]+[0-9]?[^0-9]+) ([0-9 ]+)/', $v, $b);
$c[$b[1][0]] = explode(' ',$b[2][0]);
}
//print_r($c);
$fild_for_sum = array('Strike Action:', 'Covert Skill:', 'troop3a');
$sum =0;
foreach ($fild_for_sum as $k) 
$sum += array_sum($c[$k]);
echo 'Sum of fileds ', implode(', ', $fild_for_sum), ' is ', $sum;
?>

Link to comment
Share on other sites

preg_match_all('/.+ [0-9]+/', $info, $a); <-- find line with numbers in it

preg_match_all('/([^0-9]+[0-9]?[^0-9]+) ([0-9 ]+)/', $v, $b); <-- separate text and numbers part

$c[$b[1][0]] = explode(' ',$b[2][0]); <-- create array who has text part for key and numbers array for value

try to print_r($c);

Link to comment
Share on other sites

How would i set each of the below using the above code sassa gave me into so that each seperate number below turns into its corsponding integer value

 

bot 0 0  0 

Units 0  0  7227 

Human Form Units 100000  930000  1478941 

Covert Operatives: 1050000 

Anti-Covert Operatives: 0 

Attack Turns: 633 

Unit Production: 4544

 

bot 0 0  0 

$unit1 = 0;

$unit2 = 0;

$unit3 = 0;

 

Units 0  0  7227 

$unit4 = 0;

$unit5 = 0;

$unit6 = 7227;

 

Human form Units 100000  930000  1478941

$unit7 = 100000;

$unit8 = 930000;

$unit9 = 1478941;

 

Covert Operatives: 1050000 

$unit10 = 1050000;

 

Anti-Covert Operatives: 0   

$unit11 = 0;

 

Attack Turns: 633 

$AT = 633;

 

Unit Production: 4544

$unitp = 4544;

 

 

but each one of the numbers after the $unit# can variy because of each person has different stats and i need these to be equal to diff. values because i will be using them for different things

Link to comment
Share on other sites

try

<?php
$info = 'bot 0 0  0 
Units 0  0  7227 
Human Form Units 100000  930000  1478941 
Covert Operatives: 1050000 
Anti-Covert Operatives: 0 
Attack Turns: 633 
Unit Production: 4544 ';
$find = array( '  ', ','); 
$replace = array(' ', '');
$info = str_replace($find, $replace, $info);
preg_match_all('/.+ [0-9]+/', $info, $a);
foreach ($a[0] as $k => $v) {
preg_match_all('/([^0-9]+) ([0-9 ]+)/', $v, $b);
$c[$b[1][0]] = explode(' ',$b[2][0]);
}
//print_r($c);
$fild_for_sum = array('bot', 'Units', 'Human Form Units','Covert Operatives:','Anti-Covert Operatives:');
$u = array('');
foreach ($fild_for_sum as $k) $u = array_merge($u, $c[$k]);
for ($i = 1; $i < 12; $i++) {
$n = 'unit'.$i;
$$n = $u[$i];
}
$AT = $c['Attack Turns:'][0];
$unitp = $c['Unit Production:'][0];
echo " unit1 = $unit1, unit2 = $unit2, unit3 = $unit3, unit4 = $unit4, unit5 = $unit5, unit6 = $unit6, unit7 = $unit7, unit8 = $unit8, unit9 = $unit9, unit10 = $unit10, unit11 = $unit11, AT = $AT, unitp = $unitp";
?>

Link to comment
Share on other sites

ok thats how you get that info now how do you get that infor out of this info???

 

recon Mission Report

Under the cover of night, your 208,000 Covert Ops sneak into the realm of Jungleman .

Your Covert Ops move stealthily through the lands of Jungleman undetected. They are able to gather many documents recording the status of weapons, army size and preparedness, and fortifications. Unfortunately, in order to avoid detection, they are not able to provide complete information. Your Chief of Intelligence provides you with the information gathered:

 

 

Army Size:

Unit Type

Attackers Defenders Untrained

 

Mercenaries 0 18  0 

Soldier 0  0  158550 

NID Agent 200  19  66897 

 

 

Military Stats

Strike Action: 24,548,048 

Defensive Action 0 

Covert Action: 22 

AntiCovert Action 22

Covert Skill: 21 

Covert Operatives: 0 

 

Anti-Covert Skill: 0 

Anti-Covert Operatives: 0 

Attack Turns: 3999 

Unit Production: 7244

Link to comment
Share on other sites

<?php
$info = 'recon Mission Report
Under the cover of night, your 208,000 Covert Ops sneak into the realm of Jungleman .
Your Covert Ops move stealthily through the lands of Jungleman undetected. They are able to gather many documents recording the status of weapons, army size and preparedness, and fortifications. Unfortunately, in order to avoid detection, they are not able to provide complete information. Your Chief of Intelligence provides you with the information gathered:


Army Size:
Unit Type
Attackers Defenders Untrained

Mercenaries 0 18  0 
Soldier 0  0  158550 
NID Agent 200  19  66897 


Military Stats
Strike Action: 24,548,048 
Defensive Action 0 
Covert Action: 22 
AntiCovert Action 22
Covert Skill: 21 
Covert Operatives: 0 

Anti-Covert Skill: 0 
Anti-Covert Operatives: 0 
Attack Turns: 3999 
Unit Production: 7244';
$find = array( '  ', ','); 
$replace = array(' ', '');
$info = str_replace($find, $replace, $info);
preg_match_all('/.+ [0-9]+/', $info, $a);
foreach ($a[0] as $k => $v) {
preg_match_all('/([^0-9]+) ([0-9 ]+)/', $v, $b);
$c[$b[1][0]] = explode(' ',$b[2][0]);
}
//print_r($c);
//$fild_for_sum = array('bot', 'Units', 'Human Form Units','Covert Operatives:','Anti-Covert Operatives:');
$fild_for_sum = array('Mercenaries', 'Soldier', 'NID Agent','Covert Operatives:','Anti-Covert Operatives:');
$u = array('');
foreach ($fild_for_sum as $k) $u = array_merge($u, $c[$k]);
for ($i = 1; $i < 12; $i++) {
$n = 'unit'.$i;
$$n = $u[$i];
}
$AT = $c['Attack Turns:'][0];
$unitp = $c['Unit Production:'][0];
echo " unit1 = $unit1, unit2 = $unit2, unit3 = $unit3, unit4 = $unit4, unit5 = $unit5, unit6 = $unit6, unit7 = $unit7, unit8 = $unit8, unit9 = $unit9, unit10 = $unit10, unit11 = $unit11, AT = $AT, unitp = $unitp";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.