I have an array already existing. Lets say it has 3 items.
$user = array('people' => 5, 'friends' => 10, 'siblings' => 7);
I can then access this array like,
echo $user['people']; // 5
echo $user['friends']; // 10
Now lets say I have another array called $person
like,
array(3) {
[0]=> array(2)
{ [0]=> string(4) "people" [1]=> string(1) "30" }
[1]=> array(2)
{ [0]=> string(6) "friends" [1]=> string(1) "22" }
[2]=> array(2)
{ [0]=> string(10) "siblings" [1]=> string(1) "71" }
}
I can access my $user
array by using the second array $person
manually by doing.
echo $user[$person[0][0]]; // Is accessing $user['people'], 5
echo $user[$person[0][1]]; // Is accessing $user['friends'], 10
echo $user[$person[0][2]]; // Is accessing $user['siblings'], 7
How can I do this dynamically (as the $person
arrays keys can change)? Let us say to use it in a function like so,
max($user[$person[0][0]], $user[$person[0][1]], $user[$person[0][2]]) // 10
If this possible?