Home > Back-end >  Change the format returned by the array
Change the format returned by the array

Time:01-03

I have the following array:

$id_utt1 = explode(',', $_GET['arr']);

$id_utt = array_unique($id_utt1);

var_dump($id_utt);

which returns the data as follows:

array(24) { [0]=> string(3) "560" [6]=> string(3) "515" [12]=> string(3) "620" [14]=> string(3) "544" [15]=> string(3) "674" [16]=> string(3) "602" [22]=> string(3) "745" [25]=> string(3) "755" [29]=> string(3) "522" [31]=> string(3) "545" [32]=> string(3) "555" [33]=> string(3) "562" [34]=> string(3) "563" [35]=> string(3) "573" [36]=> string(3) "584" [39]=> string(3) "643" [41]=> string(3) "696" [42]=> string(3) "698" [43]=> string(3) "699" [44]=> string(3) "700" [45]=> string(3) "709" [46]=> string(3) "730" [47]=> string(3) "735" [49]=> string(3) "590" }

But I need the array to keep the data this way:

[560,515,620,544,674,602,745,755,522,545,555,562,563,573,584,643,696,698,699,700,709,730,735,590]

CodePudding user response:

Your return is an associative array, you need to keep the values only.

You can use :

$array = array_values($id_utt);

More explications here Convert an associative array to a simple array of its values in php

  •  Tags:  
  • php
  • Related