get specific key value from array php
snippet in php

php count array elements with specific key

user9706

$cnt = count(array_filter($array,function($element) {
  return $element['your_key']=='foo';
}));

get key of value array php

user3319


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

get specific key value from array php

user7326

$ids = array_column($users, 'id');

get key of array element php

user5018

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

php order array by specific key

user597

    function cmp($a, $b)
    {
        return strcmp($a->display_name, $b->display_name);
    }

    usort($blogusers, "cmp");

    foreach ($blogusers as $bloguser)
    {
        ...