Has anyone had any experience using PHP to find the balance point of an array?
I'm struggling to find a solution or any information on how to achieve this.
Has anyone had any experience using PHP to find the balance point of an array?
I'm struggling to find a solution or any information on how to achieve this.
<?php
$arrayData = array(1,2,3,2,1);
for($i=0;$i<count($arrayData);$i++)
{
$sumLeft = 0;
$sumRight = 0;
for($key=0; $key <= $i; $key++)
{
$sumLeft += $arrayData[$key];
}
for($key=$i; $key < count($arrayData); $key++)
{
$sumRight += $arrayData[$key];
}
if($sumLeft == $sumRight)
{
echo "Array Possition : "$i;
}
}
?>