Answers for "how to access array using key in php"

PHP
2

how to access array using key in php

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
Posted by: Guest on February-26-2022
0

php array access by key

$newarray = array();
foreach($shop as $key=>$value) {
    $newarray[$key]['Title'] = $value['Title'];
    $newarray[$key]['Number'] = $value['Number'];
}
echo "<pre>";print_r($newarray);
Posted by: Guest on April-30-2021

Code answers related to "how to access array using key in php"

Browse Popular Code Answers by Language