Solved

Finding values in an array using criteria - php and mysql

Posted on 2008-10-18
4
185 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

735 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