Skip to content

Commit

Permalink
added new option for reindexing an object
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris DeGroat committed Oct 9, 2014
1 parent 4915293 commit 49d369f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions misc.php
Expand Up @@ -17,14 +17,21 @@ public static function user_ip()
return $_SERVER['REMOTE_ADDR'];
}

public static function reindex($array, $field)
public static function reindex($array, $field, $as_object = FALSE)
{
$new_array = array();
$array = (array) $array;
foreach($array as $a)
{
$a = (array) $a;
$new_array[$a[$field]] = $a;
if(!$as_object)
{
$a = (array) $a;
$new_array[$a[$field]] = $a;
}
else
{
$new_array[$a->$field] = $a;
}
}
return $new_array;
}
Expand Down

0 comments on commit 49d369f

Please sign in to comment.