LoginSignup
0
0

More than 5 years have passed since last update.

数値添え字配列の結合はarray_mergeで

Posted at

毎回ぐぐってる気がするので書いときます^^;

  • キーはキープされません。
  • キーは0から振り直されます。
<?php
$base = ['a', 'b', 'c'];
$add = ['d', 'e', 'f'];

$merge = array_merge($base, $add);
var_dump($merge); // ['a', 'b', 'c', 'd', 'e', 'f']

// 数値添え字が同じでも別々でも
$base = [0 => 'a', 1 => 'b', 2 => 'c'];
$add = [0 =>'d', 3=>'e', 4=>'f'];
$merge = array_merge($base, $add);
var_dump($merge); // ['a', 'b', 'c', 'd', 'e', 'f']

?>

paiza IOでの実行例数値添え字の配列結合(PHP)

0
0
0

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
0
0