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

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 foreach loop 
Php :: vscode open php tag autocomplete 
Php :: disable laravel passport 
Php :: pass in php 
Php :: eloquent with 
Php :: laravel launch only one dusk test 
Php :: break and continue in laravel 
Php :: php switch statement 
Php :: how to go to another folder in php 
Php :: installing bootstrap ui in laravel app 
Php :: Laravel 5.4 Route back in blade 
Php :: why do we use php exceptions 
Php :: Modes for File Read PHP 
Php :: php absolute value 
Php :: installing bootstrap on laravel8 
Php :: how to use plugin shortcode in wordpress template 
Php :: how to get parameter from url in laravel blade 
Php :: erreur php 
Php :: insert data in database using seeder in laravel 
Php :: Clear from faild_jobs laravel 
Php :: get 2 days before date in php 
Php :: php get filetype 
Php :: get database columns laravel 
Php :: how to create controller inside folder in laravel 
Php :: datetime blade laravel 
Php :: laravel button redirect 
Php :: program logic for second largest number in an array in php 
Php :: laravel nested query builder 
Php :: laravel npm build production 
Php :: migration rename column laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =