I was trying to make a program to do synthetic division which requires factoring so I wrote this function to factor an integer which works, but it never changes the values of the php array $factors. Any help will be greatly appreciated.
$factors=array();
$i;
function factor($x){
if($x==0){
echo "(0,0)";
} else {
$n=false;
if($x<0) {
$x=abs($x);
$n=true;
}
for($i=2; $i<=$x; $i++) {
if($x%$i==0){
if($n){
$factors[(count($factors))]=(-1*($x/$i));
$factors[(count($factors))]=($i);
$factors[(count($factors))]=($x/$i);
$factors[(count($factors))]=(-1*$i);
} else {
$factors[(count($factors))]=($x/$i);
$factors[(count($factors))]=($i);
}
}
}
}
}
factor(-4);