“PHP in Arrayschlüssel” Code-Antworten

PHP -Schlüssel in Array existiert


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

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

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

Misty Manatee

PHP Array Index existiert

// 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 Arrayschlüssel

<?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 -Tasten von 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

Ähnliche Antworten wie “PHP in Arrayschlüssel”

Fragen ähnlich wie “PHP in Arrayschlüssel”

Weitere verwandte Antworten zu “PHP in Arrayschlüssel” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen