Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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);
Comment

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
Comment

PREVIOUS NEXT
Code Example
Php :: php get slug 
Php :: real time update using ajax php 
Php :: php get all array keys in json 
Php :: cut the first character in php 
Php :: get specific word from string php 
Php :: wordpress widget current year 
Php :: how to insert data in table and fetch in wordpress 
Php :: worpdress pods taxonomy get custom field 
Php :: how to redirect to another page in php after submit 
Php :: collection get first element laravel 
Php :: laravel model soft delete 
Php :: use smarty variable in php 
Php :: remove more than one space in string php 
Php :: symfony messenger transport 
Php :: laravel logs 
Php :: PHP str_repeat — Repeat a string 
Php :: php socket connect 
Php :: Arr::only laravel 
Php :: laravel api cors localhost issue 
Php :: PHP | Send Attachment With Email 
Php :: eloquent insert 
Php :: PHP array_merge() Function 
Php :: mp3 file upload code in php 
Php :: how to wirte laravel dd function in php 
Php :: Download any version of xampp 
Php :: how to create foreign key in laravel 
Php :: add phpmyadmin login linux 
Php :: find substring php 
Php :: bootstrap is not defined in laravel 
Php :: how to manually remove cache in laravel 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =