index firstname lastname age [0] Mary Johnson 25 [1] Amanda Miller 18 [2] James Brown 31 [3] Patricia Williams 7 [4] Michael Davis 43 [5] Sarah Miller 24 [6] Patrick Miller 27 he above dataset in array, Write PHP code to sort thes nding order and print these data as the previous table
i need sol quickly !!!
Steps involved to produce the desired output can be followed as :
a) Create a PHP array to consider the given dataset. It is important to notice that the given table has rows and columns so the array should be multi-dimensional.
b)Add the values into the array according to the given dataset.
c)Sort the array in ascending order.
d)Print the array.
e)Design the output in a tabular manner.
To insert the values of the given dataset, a two-dimensional array, along with row and column values, is declared first. Here given table has 7 records so this two-dimensional array should consist of six one-dimensional arrays, each of them has values of horizontal cells of the given table.
For example, the two-dimensional array is named as $details where the values are inserted as below :
$details = array (
array("[0]", "Mary", "Johnson", 25),
array("[1]","Amanda","Miller", 18),
array("[2]","James", "Brown", 31),
array("[3]", "Patricia", "Williams", 7),
array("[4]", "Michael" , "Davis" , 43),
array("[5]", "Sarah", "Miller" , 24),
array("[6]" , "Patrick" , "Miller" , 27),
);
Next, the sort() function in PHP arranges the array elements in a specific ascending order. The syntax to use the function is as below :
sort(array_variable)
So, for the above example, the elements of $details can be sorted by using the following coding snippet:
sort($details)
To print this array, print_r($details) can be used. But here the desired output should in a tabular form. So the table elements should be used for designing the output.
Step by step
Solved in 3 steps with 1 images