Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

check array has keys in php

<?php

// The values in this arrays contains the names of the indexes (keys) 
// that should exist in the data array
$required = array('key1', 'key2', 'key3');

$data = array(
    'key1' => 10,
    'key2' => 20,
    'key3' => 30,
    'key4' => 40,
);

if (count(array_intersect_key(array_flip($required), $data)) === count($required)) {
    // All required keys exist!
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #array #keys #php
ADD COMMENT
Topic
Name
5+5 =