Solved

Finding values in an array using criteria - php and mysql

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to insert record into a table 2 29
write screen output to text file 21 45
How can I make this form submit to itself? 10 25
PHP Query return divisible by 3 3 13
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

816 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