1. ## php maths

is there an example at all where i can do a sum in php 1 +3 = answer?

2. \$result = \$number1 + \$number2;

3. Uh oh... Remember this thread?

PHP Code:
if(== 4){
echo

4. Originally Posted by awright418
yeah

5. Originally Posted by awright418

PHP Code:
if(== 4){
echo

Heh, I'm up for some fun

PHP Code:
function sum(\$arg1\$arg2)
{

\$x 0;
for (
\$i 0\$i \$arg1\$i++)
{

\$x++;
}

for (
\$i 0\$i \$arg2\$i++ )
{

\$x++;
}
return
\$x;
}

echo
sum(4,6);

6. Or make it handle a variable amount of numbers
PHP Code:
function sum()
{

\$args function_get_args();

\$sum 0;

foreach(
\$args AS \$arg)
{
if(
is_numeric(\$arg
{
for(
\$i 0\$i \$arg\$i++ )
{

\$sum++;
}
}
}

return
\$sum;
}

echo
sum(4,6,6,7,4,3);

7. Ooh, let the contraptions begin:
PHP Code:
<?php
class Count{
protected
\$Raw = array();
function
for(
\$i 0\$i \$Number\$i++){

\$this->Raw[] = 1;
}
}
function
GetRaw(\$Recursion 0){

\$Count = -1;
foreach(
range(0Count(\$this->Raw)) as \$Number){

\$Count -= \$Number 1;

\$Count += \$Number;
}
if(
\$Recursion == 1000) return \$Count;
return
\$this->GetRaw(\$Recursion 1);
}
function
GetSum(){
return
\$this->GetRaw();

\$Count 0;
foreach(
range(0Count(\$this->GetRaw())) as \$Number){

\$Count \$Number;
}
return
\$Count;
}
}
\$Count = new Count();
echo
\$Count->GetSum();
Off Topic:

@OP, don't take that code seriously

8. This one uses ASCII to iterate

Can handle numbers up to 1000 characters long, though, it is a bit of a memory hog

PHP Code:
<?php

class Sum
{
private
\$asciiArray;

public function
Sum()
{
for(
\$i 0\$i 1000\$i++)
{

\$this->asciiArray[\$i] = 48;
}

}

public function
{
if (
is_numeric(\$number) == false) return false;

if(
strlen(\$number) == 1)
{
for(
\$i 0\$i \$number\$i++)
{

\$this->recursiveIterator(0);
}
}
else
{

\$splitNumber str_split(\$number);

\$revSplitNumber array_reverse(\$splitNumber);

for(
\$i 0\$i count(\$revSplitNumber); \$i++)
{
if(
\$revSplitNumber[\$i] > 0)
{
for(
\$x 0\$x \$revSplitNumber[\$i]; \$x++)
{

\$this->recursiveIterator(\$i);
}
}
}
}

}

public function
printSum()
{

\$print array_reverse(\$this->asciiArray);

\$hitNumber false;

foreach(
\$print AS \$ascii )
{

\$number chr(\$ascii);
if(
\$hitNumber == false && \$number 0)
{

\$hitNumber true;
}
if(
\$hitNumber == true)
{
echo
\$number;
}

}
}

private function
recursiveIterator(\$x)
{

\$this->asciiArray[\$x]++;

if(
\$this->asciiArray[\$x] > 57)
{

\$this->asciiArray[\$x] = 48;

\$this->recursciveIterator(\$x 1);
}
}
}

\$Sum = new Sum();
\$Sum->printSum();

9. Do you mean let the user submit a string that contains "1 + 3" and you provide the answer? Like

<input name="equation" value="1 + 3">

Like how google does it when you type 1 + 3 into thier search engine? (try it)

10. Code:
php -r "\$size=2;\$px=array('1'=>array(0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,1,1,0),'2'=>array(0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0),'3'=>array(0,1,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,1,1,0),'4'=>array(0,1,0,1,0,0,1,0,1,0,0,1,1,1,0,0,0,0,1,0,0,0,0,1,0),'5'=>array(0,1,1,1,0,0,1,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0),'6'=>array(0,0,1,1,0,0,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,1,0,0),'7'=>array(0,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0),'8'=>array(0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0),'9'=>array(0,0,1,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,1,0,0),'0'=>array(0,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,0),'-'=>array(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),'.'=>array(0,0,0,0,0,0,0,0,0,0,0,0,0,1,0));\$sum=strval(floatval(\$argv[1])+floatval(\$argv[2]));for(\$r=0,\$rr=0;\$r<5*\$size;\$r++,\$rr=floor(\$r/\$size)){for(\$d=0;\$d<strlen(\$sum);\$d++){\$a=\$px[\$sum[\$d]];for(\$x=count(\$a)/5,\$i=\$rr*\$x;\$i<\$x+\$rr*\$x;\$i++){echo str_repeat((\$a[\$i]===1)?'#':' ',\$size);}}echo \"\n\";}" x y
Replace x and y with the numbers you wish to add. You can also change the size by editing \$size in the source code.

Example:
Code:
> php -r "\$size=2;\$px=array('1'=>array(0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,1,1,0),'2'=>array(0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0),'3'=>array(0,1,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,1,1,0),'4'=>array(0,1,0,1,0,0,1,0,1,0,0,1,1,1,0,0,0,0,1,0,0,0,0,1,0),'5'=>array(0,1,1,1,0,0,1,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0),'6'=>array(0,0,1,1,0,0,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,1,0,0),'7'=>array(0,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0),'8'=>array(0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0),'9'=>array(0,0,1,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,1,0,0),'0'=>array(0,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,0),'-'=>array(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0),'.'=>array(0,0,0,0,0,0,0,0,0,0,0,0,0,1,0));\$sum=strval(floatval(\$argv[1])+floatval(\$argv[2]));for(\$r=0,\$rr=0;\$r<5*\$size;\$r++,\$rr=floor(\$r/\$size)){for(\$d=0;\$d<strlen(\$sum);\$d++){\$a=\$px[\$sum[\$d]];for(\$x=count(\$a)/5,\$i=\$rr*\$x;\$i<\$x+\$rr*\$x;\$i++){echo str_repeat((\$a[\$i]===1)?'#':' ',\$size);}}echo \"\n\";}" 95 21.1
##        ##        ####            ##
##        ##        ####            ##
####      ####      ##              ####
####      ####      ##              ####
##        ##      ####              ##
##        ##      ####              ##
##        ##      ##  ##            ##
##        ##      ##  ##            ##
######    ######      ##      ##    ######
######    ######      ##      ##    ######

11. Or using multiplication to calculate the result of an addition:
PHP Code:
\$number1 23;

\$number2 19;

echo

12. I wanna see the genetic mutation method again lol

13. Originally Posted by Mike4x4s
is there an example at all where i can do a sum in php 1 +3 = answer?
PHP Code:
echo 4

14. ...or maybe some shell help:
PHP Code:
exec('echo \$((3 + 1))'\$result);
echo
array_pop(\$result);
with the much simpler and easy to read, single line alternative using the backtick operator:

PHP Code:
echo trim(array_popexplode("\n"trim(`echo \$((3 + 1))`) ) ) );

15. echo \$x + \$y

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•