?
Solved

Finding values in an array using criteria - php and mysql

Posted on 2008-10-18
4
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

800 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