-2

I have an array in php Contents of array are

print_r($room_array);

Array ( [1] => 102 );

Now how do I change the value of index 1 to index 0

Sam
  • 2,935
  • 1
  • 19
  • 26
  • 1
    I take it that 'change the value of one index to another index' means that you want to change the key? And how does the error relate to your question? What code did you run to get that error? – underscore_d Apr 10 '18 at 16:07
  • 1
    Possible duplicate of [Rebase array keys after unsetting elements](https://stackoverflow.com/questions/5943149/rebase-array-keys-after-unsetting-elements) – aynber Apr 10 '18 at 16:18
  • 1
    Other duplicate: https://stackoverflow.com/questions/7536961/reset-php-array-index – aynber Apr 10 '18 at 16:19
  • 1
    [Please, do more research](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) then **post what you've tried** with a **clear explanation of what isn't** working and provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Read [How to Ask a good question](https://stackoverflow.com/help/how-to-ask). Be sure to [take the tour](https://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/questions/347937/im-new-to-stack-overflow-what-are-some-things-i-should-do-and-what-things-wil). – adprocas Apr 10 '18 at 16:23

2 Answers2

0

First this is a very unclear question but this is what I think will solve your problem.

foreach($room_array as $key=>$value) {
    unset($room_array[$key]);
    $room_array[0] = $value;
} 

I know this is a very hard coded and not scalable script, but the question is very unclear.

0

you can use :

print_r([...$room_array]);

or

print_r(array_values($room_array));

Regards,