Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

連想配列

Posted at

連想配列

基本的な内容は通常の配列と同じ

書き方

<?php

$arry = [
  'name' => 'Bob',
];
echo $arry['name'];

実行結果

Bob

配列の中に配列も含めれる

<?php

$arry = [
  'name' => 'Bob',
  'sports' => ['baseball', 'swimming'];
];
echo $arry['sports'][1];

実行結果

swimming

数値も格納可

<?php

$arry = [
  'age' => '12',
];
$arry['age'] += 24;
echo $arry['age'];
  • array_shiftも使える(けどあまり使わない)
  • 削除はunsetを使うことが多い

unset

$arry = [
  'name' => 'BOb',
  'age' => '12',
  'sports' => ['baseball', 'swimming']
];

unset($arry['name']);

こちらでnameの配列を削除

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?