okay firstly be easy on me :) Okay i have an sorted array based on their element 'sum'. The code look like this :
$array2[] = array('age'=>$cases['age'],'allergies'=>$cases['allergies'],'vege'=>$cases['vege'],'bmi'=>$cases['bmi'],'solution'=>$cases['solution'],'sum'=>$sum);
function sortByOrder($a, $b) {
return $a['sum'] - $b['sum'];
}
usort($array2, 'sortByOrder');
echo '<pre>';
print_r(array_values($array2));
echo '</pre>';
So the output from it would be :
Array
(
[1] => Array
(
[age] => young
[allergies] => eggs
[vege] => yes
[bmi] => normal
[solution] => As a young adult you need to eat more calcium preferable three servings from dairy group each day such as milk, one small pot yogurt and cheese.
[sum] => 2
)
[2] => Array
(
[age] => young
[allergies] => milk
[vege] => yes
[bmi] => underweight
[solution] => As a young adult you need to eat more calcium preferable three servings per day. Since you are allergies to milk you can eat broccoli spinach and beans to required calcium. Try fortified wholegrain cereals.
[sum] => 4
)
[3] => Array
(
[age] => young
[allergies] => milk
[vege] => yes
[bmi] => underweight
[solution] => As a young adult you need to eat more calcium preferable three servings per day. Since you are allergies to milk you can eat broccoli spinach and beans to required calcium. Try fortified wholegrain cereals.
[sum] => 4
)
)
Now i only want 2 last element from that array, then i use this code :
$res = array_slice($array2, -2, 2, true);
Then from this array $res i want one random element from it. How do i do that? I want my output (only the solution) to be like this :
['solution'] => As a young adult you need to eat more calcium preferable three servings per day. Since you are allergies to milk you can eat broccoli spinach and beans to required calcium. Try fortified wholegrain cereals. A proper breakfast will provide fibre and several key vitamins.
Aucun commentaire:
Enregistrer un commentaire