General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 11th, 2003, 02:31 PM
Orez Orez is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 3 Orez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Search For A Range In A Multi-Dimensional Array And Displaying It

I’m trying to have this code display only items from 9.95 to 37.95. I know it may be a basic concept but I can’t seem to figure it out. Does anyone know how to do this?

<?php
$price = 19.95;
$birds = array (
'21064' => array('number' => '21064', 'name' => 'Porcelain Cardinals', 'price' => 19.95),
'21065' => array('number' => '21065', 'name' => 'Porcelain Canaries', 'price' => 19.95),
'21066' => array('number' => '21066', 'name' => 'Porcelain Doves', 'price' => 19.95),
'21681' => array('number' => '21681', 'name' => 'Porcelain Cardinal On Branch', 'price' => 9.95),
'21683' => array('number' => '21683', 'name' => 'Porcelain White Dove', 'price' => 17.95),
'22798' => array('number' => '22798', 'name' => 'Porcelain Baby Cardinals', 'price' => 14.95),
'22801' => array('number' => '22801', 'name' => 'Porcelain Cardinals On Branch', 'price' => 37.95),
'22802' => array('number' => '22802', 'name' => 'Porcelain Bluejays On Branch', 'price' => 37.95),
'22803' => array('number' => '22803', 'name' => 'Porcelain Doves On Branch', 'price' => 37.95),
'24795' => array('number' => '24795', 'name' => 'Porcelain Eagle With 2 Flags', 'price' => 29.95)
);
foreach ($birds as $key=>$value) {
if (is_array($value)) {
foreach ($value as $subkey1=>$subvalue1) $birds = array_unique($birds); {
if ($subvalue1 == $price) echo "$value[number]&nbsp;&nbsp;$value[name]&nbsp;&nbsp;$value[price]<br>";
}
}
}
?>

Reply With Quote
  #2  
Old May 11th, 2003, 08:04 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Is this not in a database? It would be extremely simplistic if it was.

If not, you would have to iterate the array and set your conditional to detect if the int is in between the two numbers:
PHP Code:
foreach( $birds as $key => $val )
{
    if ( ( ( int )
$val['price'] >= ( int )9.95 ) && ( ( int )$val['price'] <= ( int )37.95 ) )
    {
        
/************************************
        It is a match - do something
        Use:
            $val['name']
            $val['number']
            $val['price']
        ************************************/
    
}

__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old May 12th, 2003, 12:18 AM
Orez Orez is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 3 Orez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the help! Your code works.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Search For A Range In A Multi-Dimensional Array And Displaying It


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway