I am having an issue showing all keys to their respective values while I am shorting this array in php.
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43", "Ben"=>"56");
ksort ($age);
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
}
The result I am getting is
Key=Ben, Value=56
Key=Joe, Value=43
Key=Peter, Value=35
The result should be
Key=Ben, Value=37
Key=Ben, Value=56
Key=Joe, Value=43
Key=Peter, Value=35
You cannot have multiple keys with the same "name".
It has to be possible to fetch a value by a unique key. Having the same key twice would give problems.
You can instead use a numeric array with sub-arrays to get around this:
Your code adjusted: