Bir SQL sorgusu bu verileri alamıyorsanız, sıralamak ki usort
and stripos
a> kullanarak; böyle bir şey yapmanız gerekir:
$arr = array(
"Babyfood, plums, bananas and rice, strained",
"Bananas, dehydrated, or banana powder",
"Bananas, raw",
"Bread, banana, prepared from recipe, made with margarine",
"CAMPBELL Soup Company, V8 SPLASH Juice Drinks, Strawberry Banana",
"CAMPBELL Soup Company, V8 SPLASH Smoothies, Strawberry Banana",
"CAMPBELL Soup Company, V8 V. FUSION Juices, Strawberry Banana",
);
function compare_position($a, $b) {
return stripos($a, 'banana') - stripos($b, 'banana');
}
usort($arr, 'compare_position');
var_dump($arr);
Eğer parametre olarak aldığı iki dizeleri "Banana" konumunu (vaka-Insentive) karşılaştırır tanımlı bir fonksiyon sahibi yani burada sıralama vardır.
And you'll get this kind of output for your array, once sorted :
$ /usr/local/php-5.3/bin/php temp.php
array(7) {
[0]=>
string(37) "Bananas, dehydrated, or banana powder"
[1]=>
string(12) "Bananas, raw"
[2]=>
string(56) "Bread, banana, prepared from recipe, made with margarine"
[3]=>
string(43) "Babyfood, plums, bananas and rice, strained"
[4]=>
string(61) "CAMPBELL Soup Company, V8 SPLASH Smoothies, Strawberry Banana"
[5]=>
string(61) "CAMPBELL Soup Company, V8 V. FUSION Juices, Strawberry Banana"
[6]=>
string(64) "CAMPBELL Soup Company, V8 SPLASH Juice Drinks, Strawberry Banana"
}
Of course, if you get that data from an SQL query, it might be easier to do some additionnal calculations on the SQL side...