Solved

Finding values in an array using criteria - php and mysql

Posted on 2008-10-18
4
180 Views
Last Modified: 2013-12-13
$variables = array(  'cf_12_1_08'=>1,
       'cf_11_1_08'=>2,
                   'cf_10_1_08'=>3,
&&..
                   'cf_1_1_00'=>108,
);
There is one negative INT in the cf_ array.
I want to look into this array and get the value (1,2 &. 108) associated with the negative INT.
I tried this but have been unable to make it work.
foreach ($variables as $letter=>$number) {
if ($query[$letter] < 0) $negative_id = $number;
}
I think it is just a minor code adjustment
At the moment with the code above, the script results in 108
Thanks for the help,
0
Comment
Question by:derekstattin
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:crush83
ID: 22749968
I don't understand where your negative INT's are? You have some sort of string acting as a key, and then an INT value paired with it. You are saying you want to retrieve 1, 2, and 108 for the negative VALUE. This doesn't make sense.
0
 

Author Comment

by:derekstattin
ID: 22750171
The negative value is the value associtated with one of the variables cf_. I want to look into the array and find the negative value, then echo the number associated with that value. For e.g. if the value of 'cf_10_1_08' = -10000, then the new variable would be 3.
I also messed up with the original question. The variable should have a $. For e.g. '$cf_10_1_08' = -10000
Sorry for the confusion
0
 
LVL 5

Accepted Solution

by:
crush83 earned 500 total points
ID: 22750255
You can't have duplicate keys in an array, so you can't have 'cf_10_1_08' = -10000 and 'cf_10_1_08' = 3. I'm still unclear as to what you are exactly attempting to do.

It sounds like you have an array with key/value pairs, and if a value is negative, you want to return the key associated with it. Is this correct?
0
 

Author Comment

by:derekstattin
ID: 22750296
Yes,
I what you said in the last sentence is right,
I posted the code and the link in the other topic you are helping me with.
thank you for your help
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now