PHP Array Length Cheating Husband Example

This simple php script uses a php array named $lover to store the names of two famous women – Beyonce Knowles and Halle Berry.

The php variable $wife is used to store the first value in the $lover array which is Beyonce, who is Jay-Z’s wife.

If there is more than one woman ($benchmark = 1) in the $lover array, then Jay-Z is considered to be a cheater with whomever else is in the $lover array.

If there are two women in the $lover array but the $other_woman is just a friend or associate, ($benchmark = 2), then Jay-Z is considered to be faithful to his $wife.

$lover[0] = ‘Beyonce Knowles’;
$lover[1] = ‘Halle Berry’;

$benchmark = 1;

$husband = ‘Jay-Z’;
$wife = $lover[0];
$other_woman = $lover[1];

$phparraylength = count($lover);
echo ‘<center>’;
echo ‘<h2>’;

$i = 0;
while($i < $phparraylength):
echo $i + 1;
echo ‘. ‘;
echo $lover[$i];
echo ‘<br />’;

echo ‘</h2>’;
echo ‘</center>’;

if($phparraylength > $benchmark):
$message = “$husband is cheating on his wife $wife with $other_woman!”;
elseif($phparraylength == $benchmark):
$message = “$husband is being faithful to his wife $wife and  $other_woman was a false rumor!”;

echo ‘<center>’;
echo ‘<h2>’;
echo $message;
echo ‘</h2>’;
echo ‘</center>’;

echo PHP_EOL