Flic Posted July 22, 2007 Share Posted July 22, 2007 I'm padding out all entries in an array to the same length as the last entry in the array which will always be the longest.Its not working and I'm not sure why, so any help would be appreciated! Its probably something small but I just can't see it.My code: while ($row = $result->fetch()) {... $packets = (count($sizes))-1; // Count the number of different packet sizes... $i=0; $slength = strlen($sizes[$packets]); // Works out the length of the last entry in sizes $plength = strlen($prices[$packets]); // Works out the length of the last entry in prices while ($i <= $packets){ str_pad($sizes[$i], $slength, STR_PAD_LEFT); // Pads all packet sizes to the length of the longest one str_pad($prices[$i], $plength, STR_PAD_LEFT); // Pads all packet prices to the length of the longest one $output3[] = '<b>'.$sizes[$i].'</b> '; $output3[] = '£'.$prices[$i]; $output3[] = '<input type="radio" name="items" value="'.$sizes[$i].'">'; $output3[] = '<input type="text" name="'.$sizes[$i].'"><br>'; $i++; } $output3[] = '</div></div>';} Thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 22, 2007 Share Posted July 22, 2007 str_pad returns the padded string, you aren't doing anything with the return value. You need to save it back in the array or into another variable. Link to comment Share on other sites More sharing options...
Synook Posted July 23, 2007 Share Posted July 23, 2007 For example $sizes[$i] = str_pad($sizes[$i], $slength, STR_PAD_LEFT); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.