Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Dedicated Hosting Superb Internet

simplilearn big data and analytics

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Buy Cool Shirts

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,300 questions

8,938 answers

573 users

How to check if a key exists in multi dimensional array with PHP

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial


10 views
asked Sep 11 by avibootz

2 Answers

0 votes
$users = [
    [
        "id" => '1234567',
        "fname" => 'Tim',
    ],
    [
        "id" => '9876563',
        "fname" => 'Tom',
    ],
    [
        "id" => '3805732',
        "fname" => 'Mr. T',
    ],
    [
        "id" => '4563524',
        "fname" => 'John',
    ]
];
 
$key = array_search(4563524, array_column($users, 'id'));
 
echo $key; 
 
 
  
/*
run: 
 
3
   
*/  

 




answered Sep 11 by avibootz
edited 5 days ago by avibootz
0 votes
$users = [
    [
        "id" => '1234567',
        "fname" => 'Tim',
    ],
    [
        "id" => '9876563',
        "fname" => 'Ben',
    ],
    [
        "id" => '3805732',
        "fname" => 'Selena',
    ],
    [
        "id" => '4563524',
        "fname" => 'Fei',
    ]
];
 
$ids = array_column($users, 'id', 'id'); 
if (isset($ids[4563524]))
    echo "key exist"; 
 
 
  
/*
run: 
 
key exist
   
*/ 

 




answered Sep 12 by avibootz
edited 5 days ago by avibootz
...