How to use key in PHP
In this article, I will explain how the key() function can be used in PHP.
key() function in PHP
Syntax
Parameter
- array array is required parameter. it is the input array to use.
Example
The following example show to how the key() function can be used in PHP.
<html>
<body>
<h3 style="color: blueviolet;">key() function example in PHP</h3>
<?php
$a = array(
'Subject1' => 'Math',
'Subject2' => 'Science',
'Subject3' => 'math',
'Subject4' => 'Math',
'Subject5' => 'Computer');
echo("Current Element Position : <br>");
while ($subject_name = current($a)) {
if ($subject_name == 'Math') {
echo key($a).'<br />';
}
next($a);
}
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here