“PHP zum Drucken von Wert, wenn der Schlüssel in Array vorhanden ist” 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 zum Drucken von Wert, wenn der Schlüssel in Array vorhanden ist

function kPrint($key,$obj){    
    return (gettype($obj)=="array"?(array_key_exists($key,$obj)?$obj[$key]:("<font color='red'>NA</font>")):(gettype($obj)=="object"?(property_exists($obj,$key)?$obj->$key:("<font color='red'>NA</font>")):("<font color='red'><font color='green'>:::Exception Start:::</font><br>Invalid Object/Array Passed at kPrint() Function!!<br> At : Variable => ".print_r($obj)."<br>Key => ".$key."<br> At File: <font color='blue'>".debug_backtrace()[0]['file']."</font><br> At Line : ".debug_backtrace()[0]['line']."<br><font color='green'>:::Exception End:::</font></font>")));
}

//call this function in echo and pass parameters like key and array/object
Dharmesh Tukadiya

Ähnliche Antworten wie “PHP zum Drucken von Wert, wenn der Schlüssel in Array vorhanden ist”

Fragen ähnlich wie “PHP zum Drucken von Wert, wenn der Schlüssel in Array vorhanden ist”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen