in_array

(PHP 4 >= 4.0.0)

in_array --  Prüft, ob ein Wert in einem Array existiert

Beschreibung

bool in_array (mixed needle, array haystack [, bool strict])

Diese Funktion sucht in haystack nach needle und gibt bei Erfolg TRUE zurück, andernfalls FALSE.

Ist der dritte Parameter strict auf TRUE gesetzt, prüft in_array() auch die Typen von needle in haystack.

Beispiel 1. in_array()

$os = array ("Mac", "NT", "Irix", "Linux");
if (in_array ("Irix", $os)) {
    print "Irix gefunden";
}

Beispiel 2. in_array() mit strict

<?php
$a = array('1.10', 12.4, 1.13);

if (in_array('12.4', $a, TRUE))
    echo &quot;'12.4' found with strict check\n&quot;;
if (in_array(1.13, $a, TRUE))
    echo &quot;1.13 found with strict check\n&quot;;
?>

// Dies wird folgendes ausgeben:

1.13 found with strict check

Siehe auch: array_search().