On 4/2/2014 9:47 AM, Kevin Burton wrote:
> On Monday, March 31, 2014 9:33:44 AM UTC-5, Jerry Stuckle wrote:
>> On 3/31/2014 9:26 AM, Kevin Burton wrote:
>>
>>> On Monday, March 31, 2014 6:35:41 AM UTC-5, Jerry Stuckle wrote:
>>
>>
>>
>>>>
>>
>>>> >> A decent idea, but much harder than it needs to be. A simple two
>>
>>>> >> dimensional array suffices for what he needs. See the other updates in
>>
>>>> >> this thread.
>>
>>>>
>>
>>>> > In order for a 2D array to work you have to change the input array and the input parameters. Right?
>>
>>>>
>>
>>>> Nope. Just make the array itself two dimensional. A lot easier than
>>
>>>> all of your code (and a lot fewer changes, also).
>>
>>>
>>
>>> But what if you can't change the input array?
>>
>>>
>>
>>
>>
>> What input array? The array is generated in the code, and the indicies
>>
>> are coming from the user - probably via either $_GET or $_POST values.
>>
>>
>>
>> He is generating this array in his code to hold the values, and needs to
>>
>> only index properly into the array to get the result he wants. No
>>
>> searching or classes needed, i.e. (after proper filtering, of course)
>>
>>
>>
>> $rate = $rates[$_POST['animal']][$_POST['color']];
>>
>>
>>
>> Much easier to understand and code.
>>
>>
>
> I guess I still don't understand. The input array is:
>
> $rates = array(
> array("animal" => 0, "color" => 0, "rate" => 5),
> array("animal" => 0, "color" => 1, "rate" => 10),
> array("animal" => 0, "color" => 2, "rate" => 15),
> array("animal" => 1, "color" => 0, "rate" => 20),
> array("animal" => 1, "color" => 1, "rate" => 25),
> array("animal" => 1, "color" => 2, "rate" => 30),
> array("animal" => 2, "color" => 0, "rate" => 35),
> array("animal" => 2, "color" => 1, "rate" => 40),
> array("animal" => 2, "color" => 2, "rate" => 45),
> array("animal" => 3, "color" => 0, "rate" => 50),
> array("animal" => 3, "color" => 1, "rate" => 55),
> array("animal" => 3, "color" => 2, "rate" => 60)
> );
>
> If $input_animal is 1 then $rates[1] will be array("animal" => 0, "color" => 1, "rate" => 10). If $input_color = 2 then $rates[1][2] will be 10. Right?
>
Yes, but this is not what we are suggesting. Please see the earlier
updates.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
|