CKTIS / PHP
Ricerca lineare
Scorrere i valori in ordine fino alla prima corrispondenza.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
array_search($needle, $haystack, true);Scorrere i valori in ordine fino alla prima corrispondenza. Il confronto stretto distingue l’intero 0 dalla stringa «0». array_search restituisce una chiave, anche 0, o false se assente. Senza ordinare bastano al massimo n prove per n voci.
$items=[0=>"0",7=>0,9=>"0"];echo json_encode([array_search("0",$items,true),array_search(0,$items,true),array_search("x",$items,true)===false]);
[0,7,true]
Esempi
<?php
$items=[0=>"0",7=>0,9=>"0"];echo json_encode([array_search("0",$items,true),array_search(0,$items,true),array_search("x",$items,true)===false]);
Risultato
[0,7,true]