Answers for "php get keys and values from array"

PHP
10

get key of value array php

<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array);   // $key = 1;
?>
Posted by: Guest on March-07-2020
0

get array key php

array_keys ($array);
// It returns an array
// more informations at https://www.php.net/manual/fr/function.array-keys.php (fr)
Posted by: Guest on October-06-2020
0

php get keys and values from array

foreach($yourArray as $key => $value) {
    echo '<a href="' . $value . '">' . $key . '</a>';
}

// OR

//Use functions
key($array);     //Returns current key
reset($array);   //Moves array pointer to first record
current($array); //Returns current value
next($array);    //Moves array pointer to next record and returns its value
prev($array);    //Moves array pointer to previous record and returns its value
end($array);     //Moves array pointer to last record and returns its value
Posted by: Guest on October-07-2021

Code answers related to "php get keys and values from array"

Browse Popular Code Answers by Language