Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php array is assoc

function isAssoc(array $arr)
{
    if (array() === $arr) return false;
    return array_keys($arr) !== range(0, count($arr) - 1);
}

var_dump(isAssoc(['a', 'b', 'c'])); // false
var_dump(isAssoc(["0" => 'a', "1" => 'b', "2" => 'c'])); // false
var_dump(isAssoc(["1" => 'a', "0" => 'b', "2" => 'c'])); // true
var_dump(isAssoc(["a" => 'a', "b" => 'b', "c" => 'c'])); // true
Comment

php is_assoc

function isAssoc(array $arr)
{
    if (array() === $arr) return false;
    return array_keys($arr) !== range(0, count($arr) - 1);
}

var_dump(isAssoc(['a', 'b', 'c'])); // false
var_dump(isAssoc(["0" => 'a', "1" => 'b', "2" => 'c'])); // false
var_dump(isAssoc(["1" => 'a', "0" => 'b', "2" => 'c'])); // true
var_dump(isAssoc(["a" => 'a', "b" => 'b', "c" => 'c'])); // true
Comment

PREVIOUS NEXT
Code Example
Php :: laravel blade multiple can 
Php :: arry to string php 
Php :: send data with url in php 
Php :: mysql between all months days even null 
Php :: drupal show php errors 
Php :: php substr_replace 
Php :: check url parameter if not redirect wordpress 
Php :: mysqli connect error 
Php :: numberformater php format to k and m 
Php :: How to execute “php artisan migrate” and other Laravel commands in remote server? 
Php :: guzzlehttp http_errors get 
Php :: symfony get api data 
Php :: table laravel 
Php :: @yield laravel 
Php :: encapsulation in php 
Php :: laravel search and return record with pagination 
Php :: php array sort 
Php :: get current content type 
Php :: php artisan websockets serve 
Php :: php find all subclasses of class 
Php :: iqbal Laravel save record in two table in one line 
Php :: php += 
Php :: php readlink 
Php :: php object to json 
Php :: laraval routing 
Php :: validate file exist php 
Php :: data type for price in laravel 
Php :: php delete file 
Php :: laravel routing 
Php :: php backend generator 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =