Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jan 232011
 

Check if an array is associative or sequential in PHP?

Answer:

In PHP, if you want to check if a given array variable is associative or sequential, you can use the following method:

<?php 

$list = array(1, 2, 3, 4, 5);
$is_sequential = array_values($list) === $list;

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>