[英]list json array within a price range in php
I am stuck with a problem. 我陷入了一个问题。 I need to list json array elements with in a range.
我需要列出一个范围内的json数组元素。 Don't know how to do........
不知道该怎么办........
Controller page 控制器页面
$search = $_POST['search'];
$cat_id = $_POST['category'];
$post1 = file_get_contents("....?search=".$search."&category=".$cat_id);
$data = CJSON::decode($post1, true);
$products = $data['products'];
$pricerange = $_POST['pricerange'];
$myArray = explode('-',$pricerange);
$a =explode('$',$myArray[0]);
$b =explode('$',$myArray[1]);
$a
is the lower limit and $b
is the upper limit, $products
is the json array that has to be listed. $a
是下限, $b
是上限, $products
是必须列出的json数组。
I need to know how to list $products
based on price range between $a
and `$b´. 我需要知道如何根据
$a
和$ b之间的价格范围列出$products
。 output of $products $ products的输出
Array
(
[0] => Array
(
[id] => 11027
[title] => SPIDERMAN ENGRAVED LIGHTER
[barcode] => LEN-0022
[qty] => 8
[url] => http://www.ebay.com/itm/-/381279328138?
[retail_price] => 9.99
[category] => Array
(
[id] => 34
[name] => ENGRAVED LIGHTERS
)
[bin] => Array
(
[id] => 346
[name] => F10
)
[images] => Array
(
[0] => Array
(
[small] => http://www.heygidday.biz/portal//timthumb.php?src=/files/products/dscn124900.jpg&w=30
[middle] => http://www.heygidday.biz/portal//timthumb.php?src=/files/products/dscn124900.jpg&w=100
[source] => http://www.heygidday.biz/portal/files/products/dscn124900.jpg
)
)
)
[1] => Array
(
[id] => 11548
[title] => SPIDER MAN Black Lighter
[barcode] => LEN-0067
[qty] => 6
[url] => http://www.ebay.com/itm/-/361369988738?
[retail_price] => 10.99
[category] => Array
(
[id] => 34
[name] => ENGRAVED LIGHTERS
)
[bin] => Array
(
[id] => 346
[name] => F10
)
[images] => Array
(
[0] => Array
(
[small] => http://www.heygidday.biz/portal//timthumb.php?src=/files/products/len-00670.jpg&w=30
[middle] => http://www.heygidday.biz/portal//timthumb.php?src=/files/products/len-00670.jpg&w=100
[source] => http://www.heygidday.biz/portal/files/products/len-00670.jpg
)
)
)
)
please help me with this....... 请在这件事上给予我帮助.......
I have created a little script for you, It should help 我为您创建了一个小脚本,应该会有所帮助
function sortbyprice($a, $b) {
return $a['retail_price'] - $b['retail_price'];
}
$result_Array = array(
array('id'=>'11027','retail_price'=>'9.99'),
array('id'=>'11548','retail_price'=>'10.99'),
array('id'=>'11528','retail_price'=>'3.99'),
array('id'=>'18548','retail_price'=>'55.99')
);
echo '<pre>';
print_r($result_Array);
usort($result_Array, 'sortbyprice');
print_r($result_Array);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.