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 #185473 is a reply to message #185472] Wed, 02 April 2014 16:57 Go to previous messageGo to previous message
Kevin Burton is currently offline  Kevin Burton
Messages: 9
Registered: March 2014
Karma:
Junior Member
That is what I meant when I said what if you cannot change the input. You replied, "what input?". The input was the array that was specified in the original question.

On Wednesday, April 2, 2014 9:51:56 AM UTC-5, Jerry Stuckle wrote:
> 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
>
> ==================
[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: Wed Nov 27 11:33:26 GMT 2024

Total time taken to generate the page: 0.04416 seconds