1

How can I change the numbers 0,1,2,3... to another numbers from another array? I have tried many examples from stackoverflow but nothing helps, or I am making a mistake.

Any help is appreciated.

$arr = array (
  0 => 
  array (
    600 => 143,
    700 => 153,
    800 => 159,
    900 => 193,
    1000 => 203,
    1100 => 228,
    1200 => 239,
    1300 => 249,
    1400 => 259,
  ),
  1 => 
  array (
    600 => 152,
    700 => 163,
    800 => 195,
    900 => 205,
    1000 => 216,
    1100 => 244,
    1200 => 255,
    1300 => 279,
    1400 => 291,
  ),
  2 => 
  array (
    600 => 159,
    700 => 194,
    800 => 206,
    900 => 217,
    1000 => 229,
    1100 => 259,
    1200 => 285,
    1300 => 298,
    1400 => 311,
  ),
  3 => 
  array (
    600 => 191,
    700 => 204,
    800 => 217,
    900 => 230,
    1000 => 242,
    1100 => 288,
    1200 => 302,
    1300 => 317,
    1400 => 331,
  )
);
2
  • It is unclear from question what output you need? Commented Feb 11, 2018 at 17:55
  • 1
    how to change 0,1,2,3.... to another numbers Commented Feb 11, 2018 at 17:58

2 Answers 2

2

if you have two arrays - one with data (the array from the question) and the second with keys

$keys = [ 101,102, 103,..];

you can make new arrray by function array_combine

$new = array_combine($keys, $arr);
Sign up to request clarification or add additional context in comments.

Comments

0

Just assign to new and unset the old

 $arr['my_new_key' ] = $arr[ 'my_old_key'];
 unset($arr[ 'my_old_key']);

in your case you could use

 $arr[1000 ] = $arr[ 0];
 unset($arr[ 0]);

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.