Solved

Finding values in an array using criteria - php and mysql

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

910 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

16 Experts available now in Live!

Get 1:1 Help Now