Answers for "find key with value php"

PHP
6

php all keys in array

<?php
$array = array(
    'fruit1' => 'apple',
    'fruit2' => 'orange',
    'fruit3' => 'grape',
    'fruit4' => 'apple',
    'fruit5' => 'apple');

$keys = array_keys($array);		// return array
$values = array_values($array);	// return array
?>
Posted by: Guest on April-29-2020
0

php find key in array

<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
    echo "The 'first' element is in the array";
}
?>
Posted by: Guest on June-23-2021
1

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'));
Posted by: Guest on May-18-2020
2

array search by key in php

$arr = array(
    "one" => 1,
    "two" => 2,
    "three" => 3,
    "seventeen" => 17
);
function find($mot){
  
  global $arr; // this is global variable
  $ok=false;
 foreach ($arr as $k => $v) 
    {
      if($k==$mot){
        return $v; $ok=true; // or return true;
      }
    }
  if(ok==false){ return -1; }  // or return false;
}

//call function
echo find("two");
Posted by: Guest on November-04-2020

Code answers related to "find key with value php"

Browse Popular Code Answers by Language