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 return validation errors 
Php :: get file extension php 
Php :: combine 2 columns search query laravel 
Php :: file exist php 
Php :: json encode decode 
Php :: end foreach loop 
Php :: php return new object 
Php :: wordpress display post categories 
Php :: php use function from same class 
Php :: Enqueue WordPress Scripts and Styles 
Php :: php combine values of two arrays 
Php :: pluck laravel 
Php :: drop column table in migration if exist in laravel 
Php :: php if elseif 
Php :: check if value change laravel 
Php :: laravel model sync 
Php :: laravel route param blade 
Php :: laravel log reader 
Php :: how to get attachments to emails php 
Php :: how naming resource routes laravel 
Php :: laravel use global variable in model 
Php :: static php 
Php :: SoapClient Laravel 8 
Php :: laravel collection get unique values 
Php :: doctrine querybuilder select alias 
Php :: php timestamp to iso8601 
Php :: install laravel on windows 
Php :: convert datetime to string in php 
Php :: trait php 
Php :: how to write orderby in join query with where clause in codeigniter 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =