|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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] $value[name] $value[price]<br>"; } } } ?> |
|
#2
|
|||
|
|||
|
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:
__________________
~ 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. |
|
#3
|
|||
|
|||
|
Thanks for the help! Your code works.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Search For A Range In A Multi-Dimensional Array And Displaying It |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|