FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Need help accessing the key array.
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Need help accessing the key array. [message #185471 is a reply to message #185448] Wed, 02 April 2014 13:47 Go to previous messageGo to previous message
Kevin Burton is currently offline  Kevin Burton
Messages: 9
Registered: March 2014
Karma:
Junior Member
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.
>
>
>
> --
>
> ==================
>
> Remove the "x" from my email address
>
> Jerry Stuckle
>
> jstucklex(at)attglobal(dot)net
>
> ==================

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?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Most secure way to reset a password via email link
Next Topic: Strange but true! Working with interfaces in PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 16:59:53 GMT 2024

Total time taken to generate the page: 0.04428 seconds