Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

array_search macht mich verrückt

Empfohlene Antworten

hi und hallo,

kann mir jemand erklären wieso hier "false" ausgegeben wird??


$arrTest = Array(0,1,2,3,4);

$key = array_search(0,$arrTest);

if($key == NULL){

     echo("false");

}

denn "0" findet sich doch im array. nämlich an stelle [0]. wenn ich nach 1 oder 2 oder .... suche wird mir nicht false ausgegeben, die zahlen werden also gefunden.

also


if($key === null){

    echo("false");

}

oder

if($key === 0){

    echo("false");

}

?

wenn ich dann aber nach -1 suche wird mir nicht false ausgegeben obwohl sich -1 ja nicht im array findet...

siehe manual:

Description

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

Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise.

Note: If needle is a string, the comparison is done in a case-sensitive manner.

Note: Prior to PHP 4.2.0, array_search() returns NULL on failure instead of FALSE.

If the optional third parameter strict is set to TRUE then the array_search() will also check the types of the needle in the haystack.

If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys() with the optional search_value parameter instead.


$arrTest = Array(0,1,2,3,4);
$key = array_search(0,$arrTest);
if(!$key){
echo "Da ist nichts drinn?!?";
} else {
echo "Juhu da ist doch was :)";
}
[/PHP]

oder:

[PHP]
$arrTest = Array(0,1,2,3,4);
$key = array_search(0,$arrTest);
if($key === false){
echo "Da ist nichts drinn?!?";
} else {
echo "Juhu da ist doch was :)";
}

tatsache, das wars. cool echt! weiss nicht welche blockade ich da wieder hatte....

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.