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

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 :: if file is not selected in file input type php 
Php :: php get first two paragraphs 
Php :: file get content php post 
Php :: how to get the previous page url in php 
Php :: laravel collection get 
Php :: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes 
Php :: isset 
Php :: match php 
Php :: display php error 
Php :: how to excluse csrf in a route laravel 
Php :: php str starts with 
Php :: laravel check if environment is production 
Php :: laravel eloquent relationship 
Php :: php artisan serve stop 
Php :: php require once 
Php :: auto reload for laravel 
Php :: Add Text After or Before on the Shop Page/Archive Page 
Php :: console.log for php 
Php :: php gravity forms display 
Php :: sqlstate[22023]: invalid parameter value: 
Php :: php get function from different file 
Php :: laravel controller subfolder 
Php :: Add button next to "ADD TO CART" on product archive 
Php :: laravel change db connection on the fly 
Php :: switch case or case php 
Php :: assocititive multi array compare php 
Php :: exit and echo php 
Php :: wp get_results count 
Php :: laravel query when 
Php :: smtp_port" setting in php.ini or use ini_set() 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =