1

How to reset the key value of an array? I have an array named $myArray like this :

Array([TF22] => Array([5] => 07.00 [6] => 09.45 [7] => 13.00)
      [TF23] => Array([8] => 07.00 [9] => 15.45))

how I can reset the array key like :

Array([TF22] => Array([0] => 07.00 [1] => 09.45 [2] => 13.00)
      [TF23] => Array([0] => 07.00 [1] => 15.45))

I have tried using array_value(), but the result :

foreach($myArray as $val) {
  $val = array_values($val);
}

Array([0] => 07.00[1] => 09.45[2] => 13.00)
Array([0] => 07.00[1] => 15.45)

Can anyone help me ? Thanks.

1
  • array_walk($myArray,function(&$value) {$value = array_values($value); }); Commented May 8, 2014 at 7:14

1 Answer 1

3

You need to loop like this...

$new_arr = array();
foreach($yourarray as $k=>$arr)
{
 $new_arr[$k] = array_values($arr);
}
Sign up to request clarification or add additional context in comments.

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.