“PHP in Array Key” Kode Jawaban

Kunci PHP dalam array ada


<?php
$search_array = array('first' => null, 'second' => 4);

// returns false
isset($search_array['first']);

// returns true
array_key_exists('first', $search_array);
?>

Misty Manatee

Indeks array php ada

// Here's our fruity array
$fruits = ['apple', 'pear', 'banana'];

// Use it in an `if` statement
if (array_key_exists("banana", $fruits)) {
 // Do stuff because `banana` exists
}

// Store it for later use
$exists = array_key_exists("peach", $fruits);

// Return it directly
return array_key_exists("pineapple", $fruits);
SmokeFrog

PHP in Array Key

<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
    echo "The 'first' element is in the array";
}
?>
Shadow

PHP Keys of Array

$array = array(0 => 100, "cor" => "vermelho");
print_r(array_keys($array));

$array = array("azul", "vermelho", "verde", "azul", "azul");
print_r(array_keys($array, "azul"));

$array = array("cor"     => array("azul", "vermelho", "verde"),
               "tamanho" => array("pequeno", "medio", "grande"));
print_r(array_keys($array));
Fernando Gunther

Jawaban yang mirip dengan “PHP in Array Key”

Pertanyaan yang mirip dengan “PHP in Array Key”

Lebih banyak jawaban terkait untuk “PHP in Array Key” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya