Re: Need help accessing the key array. [message #185448 is a reply to message #185447] |
Mon, 31 March 2014 14:33 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
|
|
|