Gmunky Posted April 26, 2007 Share Posted April 26, 2007 I have an array : Array ( [0] => 10078 [9] => 10293 [10] => 10088 [11] => 10237 [12] => 10211 [13] => 10282 [14] => 10300 [15] => 10110 [16] => 10077 [19] => 10063 [21] => 10296 [22] => 10280 [23] => 10082 [27] => 10079 [29] => 10080 [30] => 10301 [31] => 10291 [32] => 10290 [33] => 10294 [34] => 10111 ) i want to be able to keep the same order of the values but i need the index to NOT skip! notice the first array is [0] and then the next one is [9]. how can change this so the array numbers are [0],[1],[2],etc.? thank you for the help! Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/ Share on other sites More sharing options...
per1os Posted April 26, 2007 Share Posted April 26, 2007 Hard to diagnose without the code that produces the array. Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239333 Share on other sites More sharing options...
Gmunky Posted April 26, 2007 Author Share Posted April 26, 2007 well I retrieve a number of records from a database and I save those ID's in an array. //Run query to retrieve all customers of the division////////////////// $query ="SELECT CUST FROM HYLIB.ARD WHERE DIVI=".$divi." ORDER BY NAME ASC"; $rs=odbc_exec($conn,$query); if(!$rs) { $errors["query"] = "ARD order# query failed"; $_SESSION["errors"]=$errors; write_to_log($errors,"stopped"); header('Location: menu.php'); exit; } //////////////////////////////////////////////////////////////////////// /////Save customer IDs in an array////////// $i=0; while (odbc_fetch_row($rs )) { $cust[$i] = odbc_result($rs,"CUST"); $i++; } $cust=array_unique($cust); print_r($cust); This is how I get : Array ( * => 10078 [9] => 10293 [10] => 10088 [11] => 10237 [12] => 10211 [13] => 10282 [14] => 10300 [15] => 10110 [16] => 10077 [19] => 10063 [21] => 10296 [22] => 10280 [23] => 10082 [27] => 10079 [29] => 10080 [30] => 10301 [31] => 10291 [32] => 10290 [33] => 10294 [34] => 10111 ) Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239340 Share on other sites More sharing options...
Gmunky Posted April 26, 2007 Author Share Posted April 26, 2007 I need the array numbers to basically just reset back to [0]. Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239345 Share on other sites More sharing options...
per1os Posted April 26, 2007 Share Posted April 26, 2007 Just a note, people love it when you use the [ code ] tags. As far as I can tell the code looks good. Give this a try. <?php //Run query to retrieve all customers of the division////////////////// $query ="SELECT CUST FROM HYLIB.ARD WHERE DIVI=".$divi." ORDER BY NAME ASC"; $rs=odbc_exec($conn,$query); if(!$rs) { $errors["query"] = "ARD order# query failed"; $_SESSION["errors"]=$errors; write_to_log($errors,"stopped"); header('Location: menu.php'); exit; } //////////////////////////////////////////////////////////////////////// /////Save customer IDs in an array////////// $i=0; $cust = array(); // make sure array is clean while (odbc_fetch_row($rs )) { $cust[$i++] = odbc_result($rs,"CUST"); } $cust=array_unique($cust); // this may be problematic?? print_r($cust); ?> The only issue I could see is if you used $cust before and it was storing some extra data. Also I am not sure if the array_unique is being problematic or not, I do not think so but yea. Something to look into if the array definition does not work. Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239349 Share on other sites More sharing options...
sasa Posted April 26, 2007 Share Posted April 26, 2007 $cust = array_slice($cust, 0, count($cust), false); print_r($cust); Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239352 Share on other sites More sharing options...
taith Posted April 26, 2007 Share Posted April 26, 2007 if you sort()/natsort() it'll realign that array for ya Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239354 Share on other sites More sharing options...
Gmunky Posted April 26, 2007 Author Share Posted April 26, 2007 Thank you for the help! this works: $cust = array_slice($cust, 0, count($cust), false); Quote Link to comment https://forums.phpfreaks.com/topic/48833-help-with-getting-rid-of-null-values-in-array/#findComment-239362 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.