KEY(3) 1 KEY(3)key - Fetch a key from an arraySYNOPSIS
mixed key (array &$array)
DESCRIPTION key(3) returns the index element of the current array position.
PARAMETERS
o $array
- The array.
RETURN VALUES
The key(3) function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not
move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key(3) returns NULL.
EXAMPLES
Example #1
key(3) example
<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
// this cycle echoes all associative array
// key where value equals "apple"
while ($fruit_name = current($array)) {
if ($fruit_name == 'apple') {
echo key($array).'<br />';
}
next($array);
}
?>
The above example will output:
fruit1<br />
fruit4<br />
fruit5<br />
SEE ALSO current(3), next(3).
PHP Documentation Group KEY(3)
Check Out this Related Man Page
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)
Hi,
I wish to store $string1 in $string1array a character in each array element.
Then i wish to echo the entire array to the screen so that it reads as the normal string again.
I have been trying with the code below but does not work. Please help...
To put string into array:
... (5 Replies)
Hi Friends
Using Redhat version 9
I have following data and me not knowing the array concept , hence please do help.
data is as below:(Date is in Dd/MM/YYYY format.)
Lf No Chq No Amount Date Name Address
123M4567891223 23456 ... (5 Replies)
Hi All,
I have a string like
echo $var
D_PROC=20080723 I_REPROC=N C_TYPE_FILE=INBOUND
Now I want it be stored in an associative array so that when we
echo $arr it should be 20080723 (5 Replies)
Hi,
I have this scenario; where there are two classes:- apple and orange.
1,2,3,4,5,6,apple
1,1,0,4,2,3,apple
1,3,3,3,3,4,apple
1,1,1,1,1,1,orange
1,2,3,1,1,1,orange
Basically for apple, i have 3 entries in the file, and for orange, I have 2 entries. Im trying to edit the file and find... (5 Replies)
I have two files:
fileA
a,b,c,10,apple
a,b,c,20,orange
a,b,c,10,grape
d,e,f,5,pear
d,e,f,100,pear
x,y,z,15,lemon
x,y,z,20,apple
x,y,z,30,grape
fileB
a,b,c,20
d,e,f,100
x,y,z,30
If col1=col1,col2=col2 and col3=3 of fileA to fileB, then take value in 4th col of fileB and replace... (5 Replies)
Hi...
i need a script to remove the space before and after the operator like( +, -, ||, &&).
Ex :
Input file
apple + manago
mango && fresh + apple fresh || fruit
Desired output:
apple+manago
mango&&fresh+apple fresh||fruit (6 Replies)
Hi,
I'm trying to write a function that reassigns an array to
another local array but the method used in reassigning
the array reformats the contents of the array which is
what I am trying to prevent.
The method used to load a file into an array works as
expected and the entire array is... (4 Replies)
hi,
I have a array like
my $array = ( "apple","ball","cat","dog","elephant");
how to push some element in the array to the first position.
for example my final array should be
elephant apple ball cat dog (5 Replies)
Need to search a pattern occurrence (count) in a specified file.
Below is the details
$ cat fruits
apple apple
ball ball
apple
ball ball ball
apple apple apple
cat cat
cat cat cat
apple
apple
Note: If I'll use the grep command with -c option then it'll count the 1st occurrence in... (6 Replies)
How do you get the contents of a line directly after a selected one? Also, how about before it? I am using CSH and don't have any GNU products installed.
Input file:
apple
orange
plum
So say I use grep on orange...how do I get plum (this line can be different so I can't just grep... (4 Replies)
Hello, I read from a book exercise for a challenge. How to print out each letter of char array a by two different pointers pa and ppa in the example?
I have tried my code for letter "r" by testing without full understanding as only the first one worked.
#include<stdio.h>
int main()
{
char... (17 Replies)
Hi,
I have a file like seen below.
apple, orange, grapes
pineapple
tomato, potato
egg
I need a output like
apple
orange
grapes
pineapple
tomato
potato (8 Replies)
I have an array of names. Each one of the name, has a number represented to it.
For example A has an ID 8, B has an ID 2.
What I am after is a for loop that when the array is in position 1, a particular variable is set to the value of position 1 in array 2
declare -a arr=("A" "B" "C"... (6 Replies)
Hi,
Let's say I have a control file like this:
RHEL apple "echo apple"
RHEL bravo "ls -l bravo*"
RHEL church "chmod church.txt"
SUSE drive "chown user1 drive.txt"
SUSE eagle "echo "eagle flies""
SUSE feather "ls -l feather*"
HP-UX google "sed 's/^Google.*$/&\
ACTION: go to... (14 Replies)