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 #185428 is a reply to message #185412] Mon, 31 March 2014 02:44 Go to previous message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma:
Senior Member
Kongthap Thammachat <kongthap(at)gmail(dot)com> wrote in news:f0d2dbc9-bd6e-4407-8d29-
a8d2e6462ebe(at)googlegroups(dot)com:

> <?php
>
> $rates = array(
> array("animal" => 0, "color" => 0, "rate" => 5),
> array("animal" => 0, "color" => 1, "rate" => 10),
[...]
> array("animal" => 3, "color" => 1, "rate" => 55),
> array("animal" => 3, "color" => 2, "rate" => 60)
> );
>
> $input_animal = 1;
> $input_color = 2;
>
> ?>
>
> How to access the $rates array to echo the associated rate of "animal" => 1 and "color"
=> 2 ? (which is 30), should i re-designed the $rates array?

Rather than redesigning the $rates array, I think you should redesign your entire approach.
Instead of loading this data into an array in php, load it into a SQL database instead. Then
your above retrieval is simple:
SELECT rate FROM rates WHERE animal = 1 AND color = 2;
[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: Sun Nov 24 19:19:08 GMT 2024

Total time taken to generate the page: 0.03979 seconds