I have array of objects, what I want to do is reset the index like 123, 150, 50 to be 0,1,2 . I have done array_values(); but it removes the first array “123”.
How can I make the index numbers starting from 0 . to make 123, 150, 50, to become 0,1,2
array(
123 =>
User::__set_state(array(
_type' => 'student',
'id' =>'23'}),
150=>
User::__set_state(array(
'_type' => 'student',
'id' =>'29'}),
50=>
User::__set_state(array(
'_type' => 'student',
'id' =>'12'})
The output
array(
150=>
User::__set_state(array(
'_type' => 'student',
'id' =>'29'}),
50=>
User::__set_state(array(
'_type' => 'student',
'id' =>'12'})
array_valuesis correct solution. The little thing is that it does not affect given array, but returns an array. So you have to assign it to another variable. For example: