waynew Posted August 1, 2008 Share Posted August 1, 2008 I have an array like so: Array ( [0] => 7 [2] => 9 ) Is there anyway to put this back so that 0 = 7 and 1 = 9? Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/ Share on other sites More sharing options...
The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 $arr = array(0 => 7, 2 => 9); print_r($arr); sort($arr); print_r($arr); Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605530 Share on other sites More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 print_r($played_fixtures); Array ( [0] => 7 [2] => 9 ) $played_fixtures = sort($played_fixtures); print_r($played_fixtures); 1 ??? Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605535 Share on other sites More sharing options...
The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 don't assign sort() to a variable. Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605536 Share on other sites More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 It's an array? Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605537 Share on other sites More sharing options...
The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 btw, this will reorder the values. if that is ok use it, otherwise: $arr = array(0 => 7, 2 => 9); $new = array(); foreach($arr as $val){ $new[] = $val; } print_r($new); Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605540 Share on other sites More sharing options...
The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 the sort function doesn't return an array, instead it returns TRUE if it sorted the array, or FALSE if it didn't sort the array. Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605542 Share on other sites More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 EDIT!!!!!!!!!!!!!!! btw, this will reorder the values. if that is ok use it, otherwise: $arr = array(0 => 7, 2 => 9); $new = array(); foreach($arr as $val){ $new[] = $val; } print_r($new); SO that will put it as array(0 => 7, 1 => 9); ??? Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605548 Share on other sites More sharing options...
The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 EDIT!!!!!!!!!!!!!!! btw, this will reorder the values. if that is ok use it, otherwise: $arr = array(0 => 7, 2 => 9); $new = array(); foreach($arr as $val){ $new[] = $val; } print_r($new); SO that will put it as array(0 => 7, 1 => 9); ??? Yes Link to comment https://forums.phpfreaks.com/topic/117731-small-index-problem-question/#findComment-605554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.