-1

Hi I have an array look like this:

Array ( [5] => 6 [6] => 7 [8] => 9 [10] => 11 [13] => 13 [22] => 23 [23] => 24 [24] => 25 [25] => 26 [29] => 30 [37] => 38 [38] => 39 [41] => 42 [44] => 45 [47] => 48 [48] => 49 [53] => 54 [57] => 58 [58] => 59 [60] => 61 [62] => 63 [68] => 69 [70] => 71 [74] => 75 )

How can get the it to look like this:

array([0] => 6 [1] => 7 [2] => 9 [3] => 11 [4] => 13 etc ) ? 
Rizier123
  • 57,440
  • 16
  • 89
  • 140
Techboy992
  • 29
  • 5

1 Answers1

0

I think you are looking for the native function of array_values():

$array  =   array(  5 => 6,
                    6 => 7,
                    8 => 9,
                    10 => 11,
                    13 => 13,
                    22 => 23,
                    23 => 24,
                    24 => 25,
                    25 => 26,
                    29 => 30,
                    37 => 38,
                    38 => 39,
                    41 => 42,
                    44 => 45,
                    47 => 48,
                    48 => 49,
                    53 => 54,
                    57 => 58,
                    58 => 59,
                    60 => 61,
                    62 => 63,
                    68 => 69,
                    70 => 71,
                    74 => 75
                );

print_r(array_values($array));

Gives you:

Array
(
    [0] => 6
    [1] => 7
    [2] => 9
    [3] => 11
    [4] => 13
    [5] => 23
    [6] => 24
    [7] => 25
    [8] => 26
    [9] => 30
    [10] => 38
    [11] => 39
    [12] => 42
    [13] => 45
    [14] => 48
    [15] => 49
    [16] => 54
    [17] => 58
    [18] => 59
    [19] => 61
    [20] => 63
    [21] => 69
    [22] => 71
    [23] => 75
)

From the manual: http://php.net/manual/en/function.array-values.php

Rasclatt
  • 12,382
  • 3
  • 23
  • 33
  • I have 2 arrays I have compared where array1 is some random numbers and array2 is a bingo card, then I have used array_intersect(array1,array2); and got the numbers that is same in the 2 arrays, so now I would like to get the KEYS in right format ([0] [1] [2] [3] ETC). Instead of [5] [6] [7]. so I can compare if there is a winner with IF / ELSE. – Techboy992 Oct 24 '15 at 10:22