I have a simple array like the following:
array 0 => string '101' 1 => string '105' 2 => string '103'
Desired result:
array(101, 105, 103)
Is this possible?
Yes, use array_values
.
array_values(array('0' => '101', '1' => '105', '2' => '103')); // returns array(101, 105, 103)
Edit: (Thanks to @MarkBaker)
If you use var_dump
on the original array and the "values only" array the output might look exactly the same if the keys are numerical and and ascending beginning from 0. Just like in your example.
If the keys are not consisting of numbers or if the numbers are "random" then the output would be different. For example if the array looks like
array('one' => '101', 'two' => '105', 'three' => '103')
the output of var_dump
looks different after converting the array with array_values
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With