I have an array of products and i want to sort them with another array.
$products = array(
0 => 'Pro 1',
1 => 'Pro 2',
2 => 'Pro 3'
);
$sort = array(1,2,0);
array_multisort($products, $sort);
Array should now be ...
$products = array(
0 => 'Pro 2',
1 => 'Pro 3',
2 => 'Pro 1'
);
I don't seem to be using array_multisort correctly. Ive tried different ways for 2 hours now...
$sortarray?array(1,2,0)it should be3,1,2, when you want2,3,1you should usearray(2,0,1)array_multisort($sort, $products), the array needs to be[2,0,1]. Think of it in terms of "I want the first element of$productsto be @ index 2, the second element to be at index 0, and the third element to be at index 1." With your current array, you just need to use some form of iteration (i.e.,array_map) as the answers given illustrate.