I am struggling to understand the use of the ArrayHelper::getValue.
I am starting to think that I completely mis-understand what it does…
I am getting a set of values from my DB like this…
seasonId count
1 9
2 6
What I want to do is use the value of ‘seasonId’ to get the value of ‘count’.
I need to perform this type of action in many places, and as a quick and dirty hack,
I have used a foreach loop to scan the array. Probably not the best way to do this…
I have two related sql query results wrapped in another array
Here is the result of print_r
Array
(
[seatstotal] => Array
(
[0] => Array
(
[seasonId] => 1
[total] => 22
)
[1] => Array
(
[seasonId] => 2
[total] => 26
)
)
[seatsfilled] => Array
(
[0] => Array
(
[seasonId] => 1
[count] => 9
)
[1] => Array
(
[seasonId] => 2
[count] => 6
)
)
)
1
[also, I don’t know what that ‘1’ at the end means…]
I make two loops through this code…
$fill_str = 'seatsfilled.' . $season['seasonId'] . '.count';
$total_str = 'seatstotal.' . $season['seasonId'] . '.total';
echo '<pre>';
echo print_r( $fill_str );
echo ' -- ';
echo print_r( $total_str );
echo '</pre>';
$filled = ArrayHelper::getValue($seasoncounts , $fill_str );
$total = ArrayHelper::getValue($seasoncounts , $total_str );
And I end up with these results…
seatsfilled.1.count1 -- seatstotal.1.total1
61 -- 261
seatsfilled.2.count1 -- seatstotal.2.total1
1 -- 1
It looks like I am retreiving the [1]=>Array values and skipping the [0]=>Array values. But I don’t know if I just don’t know how to use getValue(), or if I am using the wrong function.
Thanks
-John