Posted By

section31 on 11/20/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jamesming


Numeric Array to Associative Array


 / Published in: PHP
 

This requires a one dimensional array.

  1. function array_numeric_to_assoc($arr) {
  2. $arr = array_values($arr);
  3. $new_arr = array();
  4. for ($i = 0, $count = count($arr); $i < $count; $i += 2) {
  5. $new_arr[$arr[$i]] = isset($arr[$i + 1]) ? $arr[$i + 1] : null;
  6. }
  7. return $new_arr;
  8. }

Report this snippet  

You need to login to post a comment.