array search by key in php
<?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;
?>
$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");
Also in PHP:
- create new seeder laravel
- Your Composer dependencies require a PHP version ">= 7.2.5". You are running 7.2.0. in
- How to display MySQL data dynamically using jQuery and PHP
- display all php erros
- error out of length in php
- adjacent post sort order by post title
- eloquent all only one culomn
- event click right mouse
- display errors on
- check string contain symbol in php
- check if character in string php
- cusatom time format to timestamp php
- check session in blade laravel
- array splice php
- check where key in associative array have a value
- array_combine function in php
- change timestamp format php
- create a laravel 7 project
- array contains key
- declare empty array php
- catching error php
- check if a word is present inside a string in php
- array_search in php
- $get url php