21
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【PHP】歯抜けになった配列の添え字を連番にする

Last updated at Posted at 2015-02-05

array_mergeを使う方法

$a = array(0=>'aaa',5=>'bbb',9=>'ccc');
$a = array_merge($a);
//=>array(0=>'aaa',1=>'bbb',2=>'ccc');

参考:PHPで歯抜け、バラバラになった配列のキーを連番にする方法

array_valuesを使う方法

$a = array(0=>'aaa',5=>'bbb',9=>'ccc');
$a = array_values($a);
//=>array(0=>'aaa',1=>'bbb',2=>'ccc');

コメントにあった通りarray_valuesの方が意図がわかりやすいかもしれない。

21
16
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?