2
我想根據MYCOUNT索引對我的數組行進行排序,該索引由我的代碼計算得出。 MYCOUNT計算的匹配字數關鍵字。我有谷歌不同的功能,但我從來沒有得到所需的結果。我是新的PHP我不知道如何做到這一點,我從來沒有在谷歌上找到可以幫助我的結果。如何使用特定鍵對數組進行排序
$word = "red pent";
$flag = true;
$main_flag = true;
$list = array();
$result = $this->db->get('products')->result_array();
foreach ($result as $product):
$main_flag = true;
$keywords = explode(';', $product['product_keyword']);
$count = 0;
foreach ($keywords as $keys) {
$search = explode(' ', $word);
$local_f = false;
foreach ($search as $w) {
if (strtolower(trim($w)) === strtolower(trim($keys))) {
$local_f = true;
$count++;
break;
}
}
}
if ($count > 0) {
$product['mycount'] = $count;
array_push($list, $product);
}
if ($main_flag) {
//array_push($list,$product);
}
endforeach;
陣列數據
Array
(
[0] => Array
(
[product_id] => 5
[product_sku] => AD021CAFOR
[product_code] => X12343
[product_name] => Ten aZ Cap
[product_price] => 600
[product_actual_price] => 2000
[product_discount] => 70
[product_gender] => MEN
[product_group] => Accessories
[product_category] => Cap
[product_sub_category] =>
[product_sport] => Training
[product_weight] =>
[outlet_id] => 1
[product_desc] => Adidas Ten aZ Cap CLIMACOOL
[product_short_desc] => Adidas Ten aZ Cap CLIMACOOL
[product_added_on] => 2014-02-20
[product_updated_on] =>
[product_image] => image1.png
[product_thumbnail] => image1.png;image2.png;image3.png;image4.png;image5.png;image6.png
[product_list_image] => rightside-list1_03.png
[product_keyword] => Red;shirt;adidas
[mycount] => 1
)
[1] => Array
(
[product_id] => 6
[product_sku] => AD021CAFRO
[product_code] => X17618
[product_name] => Ess 3S fit Cap
[product_price] => 600
[product_actual_price] => 2000
[product_discount] => 70
[product_gender] => MEN
[product_group] => Accessories
[product_category] => Cap
[product_sub_category] =>
[product_sport] => Training
[product_weight] =>
[outlet_id] => 1
[product_desc] => The adidas Performance ESS 3S Cap has a curved peak and features neon adidas 3 stripes detailing on the front. The cap is made from a breathable, 100% cotton fabric and has an adjustable strap on the back.
[product_short_desc] => Essentials 3 Stripes Cap
[product_added_on] => 2014-02-20
[product_updated_on] =>
[product_image] => image1.png
[product_thumbnail] => image1.png;image2.png;image3.png;image4.png;image5.png;image6.png
[product_list_image] => rightside-list1_03.png
[product_keyword] => red;pent;outfiters
[mycount] => 2
)
)