Question about sorting -- how to pass an array to a function
Hi, guys
I just wanted to sort the elements of an array ascendingly.
I know the following code does work well:
However, I wanted to write a function named "sort" and pass the array as argument to the function.
I know the following code doesn't work:
And I know it'll be better by using the command "eval" to pass the array to the function like this:
but I can't put it to the correct place in the function.
So please give me some ideas~~ Thx
I want to pass an array in my function, And my function will be changing the elements of the array in the fuction, but it should not affect the values in my array variable of main function (1 Reply)
HI all
I have a code like
##############################################
minyear()
{
curryear=$1
echo $curryear
}
##Main Program ##
minyear
exit
#######
when i execute "sh scriptname 2005" output should be like 2005 but the output is blank.
I guess i need to pass parameter to... (3 Replies)
Hi,
I have an output generated from a shell script like;
0x41,0xF2,0x59,0xDD,0x86,0xD3,0xEF,0x61,0xF2
How can I pass this value to the C function, as below;
int main(int argc, char *argv) {
unsigned char hellopdu={above value};
}
Regards
Elthox (1 Reply)
I have the following code :
function1 ()
{
print "January"
}
function2()
{
case $1 in
January)
print "Dzisiaj mamy styczen"
;;
*)
;;
}
main()
{ (1 Reply)
hi,
I have a array say
SAP_ARRAY="s1.txt"
SAP_ARRAY="s2.txt"
how can i pass this full array to a function.
here is the sample code i am using..
CHECK_NO_FILES()
{
FARRAY=$1
echo "FARRAY = $FARRAY"
echo "FARRAY = $FARRAY"
............... (5 Replies)
There are two parts to this. In the first part I need to read a list of files from a directory and split it into 4 arrays. I have done that with the following code,
# collect list of file names
STATS_INPUT_FILENAMES=($(ls './'$SET'/'$FOLD'/'*'in.txt'))
# get number of files... (8 Replies)
Hi All
I have multiple arrays like below.
set -A val1 1 2 4 5
set -A val2 a b c d
.
.
.
Now i would like to pass the individual arrays one by one to a function and display/ do some action.
Note : I am using ksh
Can you please advise any solution...
Thanks in advance. (7 Replies)
Hi,
I am creating filesystem for block device, but I want to pass array value one by one acording to block device count.
$tmp1 = block device count 3
$blockdevice =
So I want to first pass sdb1 alone in loop, how to take only block device seprately from $blockdevice array. (1 Reply)
updateEnvironmentField() {
linewithoutquotes=`echo $LINE | tr -d '"'`
b()
}
I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script (1 Reply)
I'm able to read & print an array in varaible called "filelist"
I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function.
Unfortunately it does not print the entire array from inside the funstion's loop.
#/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies
LEARN ABOUT PHP
arsort
ARSORT(3) 1 ARSORT(3)arsort - Sort an array in reverse order and maintain index associationSYNOPSIS
bool arsort (array &$array, [int $sort_flags = SORT_REGULAR])
DESCRIPTION
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with.
This is used mainly when sorting associative arrays where the actual element order is significant.
PARAMETERS
o $array
- The input array.
o $sort_flags
- You may modify the behavior of the sort using the optional parameter $sort_flags, for details see sort(3).
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
arsort(3) example
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val
";
}
?>
The above example will output:
a = orange
d = lemon
b = banana
c = apple
The fruits have been sorted in reverse alphabetical order, and the index associated with each element has been maintained.
SEE ALSO asort(3), The comparison of array sorting functions.
PHP Documentation Group ARSORT(3)