Tuesday 15 September 2015

PHP: Undefined offset 1 error -


I am trying to format the number with the K, M, B, T format after 1000, but I Getting this message: / P>

Notice: Undefined Offset: 1

I do not understand what is wrong and how to fix the problem.

  $ X = round ($ num); $ X_number_format = number_format ($ x); $ X_array = Explosion (',', $ x_number_format); $ X_parts = array ('k', 'm', 'b', 't'); $ X_count_parts = Count ($ x_array) - 1; $ X_display = $ x; $ X_display = $ x_array [0] ((int) $ x_array [1] [0]! == 0? '. $ X_array [1] [0]:' '); $ X_display = $ X_parts [$ x_count_parts - 1]; Return $ x_display;   

After the explosion var_dump () result $ x_array; is

  array (1) {[0] => The string (1) "1"}   

This is the right after your first line: < Pre> returns $ x if ($ x <1000);

Edit (simple approach; complete function):

  If ($ x <1000) return round ( $ X)); Otherwise ($ x & lt; 1000000) return goal ($ x / 1000) 'K'; Second round back ($ x / 1000000). 'M';    

No comments:

Post a Comment