1<?php
2$fruit = array("apple","banana","mango","orange","strawbary");
3
4sort($fruit); //arrange in ascending order
5echo "<pre>";
6print_r($fruit);
7
8rsort( $fruit); //sort in descending order
9foreach($fruit as $val)
10{
11 echo $val."<br>";
12}
13
14$girl = array("krisha"=>20,"yashvi"=>30,"ritu"=>4,"pinal"=>80);
15asort($girl); //sort in ascending order according to value
16print_r($girl);
17
18ksort($girl); //sort in ascending order according to key
19print_r($girl);
20
21arsort($girl); //sort in descending order according to value
22print_r($girl);
23
24krsort($girl); //sort in descending order according to key
25print_r($girl);
26?>
1$price = array();
2foreach ($inventory as $key => $row)
3{
4 $price[$key] = $row['price'];
5}
6array_multisort($price, SORT_DESC, $inventory);
1
2<?php
3
4$fruits = array("lemon", "orange", "banana", "apple");
5sort($fruits);
6foreach ($fruits as $key => $val) {
7 echo $val;
8}
9/*
10OUTPUT:
11apple
12banana
13lemon
14orange
15*/
16?>
17
18
1
2<?php
3
4$fruits = array("Zitrone", "Orange", "Banane", "Apfel");
5sort($fruits);
6foreach ($fruits as $key => $val) {
7 echo "fruits[" . $key . "] = " . $val . "\n";
8}
9
10?>
11
12