0

I have an array of values:

Array ( [0] => hello [5] => Im [50] => from [1032] => Europe [1039] => where [1117] => are [1137] => you [1873] => from? ) 

What is the best way to unset these values and move everything to front ?

To be like this:

 Array ( [0] => hello [1] => Im [2] => from [3] => Europe [4] => where [5] => are [6] => you [7] => from? ) 

4 Answers 4

6

Use array_values.

$myarray = array_values($myarray);
Sign up to request clarification or add additional context in comments.

Comments

0

try with foreach

foreach($arr as $v) {
  $newarr[] = $v;
}

Comments

0

try this -

$arr = array();
foreach($arr as $value) {
   $arr[] = $v;
}

Comments

0

set an arbitrary array then use a foreach loop:

foreach ($currentArray as $curr) {
    $arbitraryArray[] = $curr;
}

then set it back to $currentArray;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.