I ran some tests and I think the solution can be implemented this way:
function breadcrumb($cat_id){
$cat_nest =
SELECT *
FROM table
WHERE cat_id = '$cat_id'
//returns 1 row;
$cat_array[$cat_id] = $cat_nest[0];
if($cat_nest[0]['cat_parent'] != 0){
$cat_array = array_merge( $cat_array, breadcrumb($cat_nest[0]['cat_parent']) );
}
return $cat_array;
}
This would maintain the IDs exactly as you need them, since this would only be merging arrays and not creating new indexes with $cat_array[]