Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

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;
Comment

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
Comment

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'));
Comment

return key position from value in array php

$i = array_search('blah', array_keys($array));
Comment

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);
}
?>

Comment

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);
}
?>

Comment

get array key php

// The easiest way

var_dump(json_decode(json_encode($value), true));
Comment

PREVIOUS NEXT
Code Example
Php :: laravel get file contents from storage 
Php :: laravel get last get request 
Php :: php print array 
Php :: laravel add utility class 
Php :: php check if query returns results 
Php :: how to exclude csrf in a route laravel 
Php :: wordpress get current logged in user 
Php :: get last id in laravel 
Php :: php foreach array 
Php :: get today datetime in php 
Php :: php multi type parameter union types 
Php :: php check for empty string 
Php :: sha256 in php 
Php :: wpdb-prepare 
Php :: how to load data from .env file in php 
Php :: collection empty laravel 
Php :: how to truncate the given string to the specified length in blade.php 
Php :: toarray php 
Php :: get name custom post type wordpress 
Php :: how login with phone in laravel 
Php :: php utf8_decode 
Php :: php date format iso 
Php :: php artisan vendor:publish 
Php :: laravel link active class 
Php :: laravel seed fresh 
Php :: php.ini path 
Php :: php shutdown function 
Php :: php curl asyc 
Php :: php add to array in loop 
Php :: carbon difference between two dates 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =