DekGenius.com
PHP
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)
get array key based on value 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;
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
get key of array element php
$people = array(
2 => array(
'name' => 'John',
'fav_color' => 'green'
),
5=> array(
'name' => 'Samuel',
'fav_color' => 'blue'
));
$found_key = array_search('blue', array_column($people, 'fav_color'));
return key position from value in array php
$i = array_search('blah', array_keys($array));
how to get array key in php
<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
// this cycle echoes all associative array
// key where value equals "apple"
for($i = 0; $i< sizeof($array);$i++){
if (key($array[$i]) == 'apple') {
echo key($array).'<br />';
}
//next($array);
}
?>
php get array key
<?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);
}
?>
get array key php
// The easiest way
var_dump(json_decode(json_encode($value), true));
Code Example
::
Php ::
::
::
::
::
::
::
::
::
::
Php ::
Php ::
::
Php ::
::
:: laravel set field unique
::
::
Php ::
::
::
::
::
Php ::
Php ::
Php ::
::
Php ::
::
© 2022 Copyright:
DekGenius.com