Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello all;

 

I have the following arrays:

 

volume_array=(100,200,350,400); and

height_array=(1,5,8,10);

 

a height_array value corresponds to a value in the volume_array with the same key.

 

Does someone know how to efficiently get the corresponding volume for a height of 7 assuming a linear relationship?

 

I have been looking at the php array functions for sometime now without any luck.

Share this post


Link to post
Share on other sites

This fetches the key from the array where the value is 7:

$key = array_keys($height_array, 7);

 

Then $volume_array[$key] gets you the value you need.

Share this post


Link to post
Share on other sites

Thanks Larry for your response.

When i try i get the message "Warning: Illegal offset type"

 

This i believe is due to the fact that ( i may be wrong though) "7" is not in the height_array it is to be extrapolated between 5 and 8.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×