Page 1 of 1

Script for Factoring a number

Posted: Sun Sep 10, 2006 5:27 pm
by Assured99
Im trying to create a script that will Factor a Number,
here is what i have so far but i keep getting this error unexpected T_INC, expecting ')' on Line 5

Code: Select all

<?php
$num = '14' ;
$counter = '1';

function factor($num , $counter++ ){
		 "$num / $counter++";
		}
		
Factor();
?>
Can any one point me in the right direction with finishing this script???

~Assured99

Posted: Sun Sep 10, 2006 5:40 pm
by volka
you cannot increment the parameter in the function declaration
function factor($num , $counter++ ){
What's the next line supposed to do?

Posted: Sun Sep 10, 2006 5:46 pm
by Assured99
Im really just trying to get it to display all the factors of a number. so im confused on where to go next.

~snapple

Posted: Sun Sep 10, 2006 5:48 pm
by Assured99
something like this mabye????

Code: Select all

<?php
$num = '14' ;
$counter = '1';

function factor($num , $counter){
		 "$result = $num / $counter++";
		 echo "$result";
		}
		
Factor();
?>
~Snapple

Posted: Sun Sep 10, 2006 7:56 pm
by sweatje
Once you get around to actually writing the logic, this blog post may help some.

Posted: Mon Sep 11, 2006 2:59 am
by volka
And please read http://de2.php.net/string
why all those quotes?