I combined two arrays to create the following array, named $group_wages_array:
Array ( [1] => 500 [4] => 44 [6] => 80 [3] => 11.25 )
I am trying to test if the array key matches X, set a variable as it's value. Here's what I have:
NOTE: This whole thing is executed in a while loop, so the value of $thegroup['group_id'] will change. I've set it's value as "6" for this example.
$thegroup['group_id'] = "6" // This particular group (for simplicity)
if (array_key_exists($thegroup['group_id'], $group_wages_array)) {
$this_wages = // Need this to be 80... how do I do it?
}
So, how do I get $this_wages to equal the key value?
You just use the key from the array to get it:
$thegroup['group_id'] = "6" // This particular group (for simplicity)
if (array_key_exists($thegroup['group_id'], $group_wages_array)) {
$this_wages = $group_wages_array[$thegroup['group_id']];
}
Also, the array keys are not 0,1,2,etc because you explicitly set them in Array ( [1] => 500 [4] => 44 [6] => 80 [3] => 11.25 )
You are trying to do:
$group_wages_array[6];
And
$thegroup['group_id'] = 6;
You can substitute this in as the key.
if (array_key_exists($thegroup['group_id'], $group_wages_array)) {
$this_wages = $group_wages_array[$thegroup['group_id']];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With