$arr=array(2,5,4,6,7,8,1);
for($i=0;$i<count($arr);$i++)
{
for($j=$i;$j<count($arr);$j++)
{
if($arr[$i] > $arr[$j])
{
$temp=$arr[$i];
$arr[$i]=$arr[$j];
$arr[$j]=$temp;
}
}
}
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php
sort() will order the array by its values without preserving the keys. Use it when array is indexed numerically or when you do not care about the keys. asort() will also sort the array by its values, but it will preserve the key -> value association.
implode() is a handy little function that pieces together values of an array by putting a "glue" in between.
You cannot sort arrays by other arrays; that wouldn't make sense, anyway.
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php
To empty an array in PHP you need to use the unset function like shown below: <?php $array = array('hello', 'hi', 'weee'); unset($array); // empty ?>
sort() will order the array by its values without preserving the keys. Use it when array is indexed numerically or when you do not care about the keys. asort() will also sort the array by its values, but it will preserve the key -> value association.
Use a for-loop starting at the length of the array and go backwards and build up a new array with the values.
To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. <?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?>
The array_map function in PHP loops over each elements of the passed array(s), and runs the given function. It then returns a new array that contains the values returned by each call to the given function.
To shuffle an array in PHP is easy to do, all you need to use is the shuffle() function like shown below: <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); shuffle($array); // array results will be randomly shuffled ?>
To merge and sort an array in PHP you need to use the array_merge() and sort() functions like shown in the example below: <?php $array1 = array(1, 5, 3, 9, 7); $array2 = array(8, 2, 6, 4, 0); // merge the arrays $merge = array_merge($array1, $array2); // 1, 5, 3, 9, 7, 8, 2, 6, 4, 0 // sort the array sort($merge); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ?>
To separate a sentence into an array of words, you can use PHP's explode() function. If $text is your sentence, then use the following: $result = explode(" ", $text);
To reverse the results in a PHP array is really simple, all you need to do is use the array_reverse() function like shown below: <?php $my_array = array(1, 2, 3); $reverse_me = array_reverse($my_array); // will be stored as 3, 2, 1 now ?>
Using the function "count". <?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // <-- outputs the number 4 ?>