Jump to content

search to specific array key


fesan

Recommended Posts

Hi, is there possible to search and "choose" a certain arrey key by user input? And when the input is not "korrect" how to choose the closest one?

 

Input = 22

 

$kz should chose key 21.3 => 1.17

$kz = array(
4.6 => 0.85,
6.1 => 0.90,
7.6 => 0.94,
9.1 => 0.98,
12.2 => 1.04,
15.2 => 1.09,
18 => 1.13,
21.3 => 1.17,
24.4 => 1.21,
27.4 => 1.24,
30.5 => 1.26,
36.6 => 1.31,
42.7 => 1.36,
48.8 => 1.39,
54.9 => 1.43,
61.0 => 1.46,
76.2 => 1.53,
91.4 => 1.59,
106.7 => 1.64,
121.9 => 1.69,
137.2 => 1.73,
152.4 => 1.77,); 

To explain some more, the array is part of a math solving. where the key is a height in meters and the value are the responding coefficient. 

$qz = 0.613 * $kz * 1 * 1 * pow($vind2, 2) *1;

 

Link to comment
Share on other sites

I don't believe you can the way you have it.

 

You can't use decimal numbers as array keys. If I copy/paste your $kz array and just print_r($kz), you get back whole numbers for the array indices instead of your decimals (24.4 becomes just 24).

 

If your keys were strings containing a decimal, then it could be workable.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.