0
1

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.

【メモ】foreach&array_pushで配列に一つずつ要素を追加したいが、一部要素のみ配列に入れたく無い場合

Posted at

配列に要素を一つずつ追加していくときに以下のようなコードで対応したが、

$team = [];
foreach($members as $member){
  array_push($team,$member);
}

$memberの中で特定の要素を配列に入れたく無い場合、

foreach($members as $member){
  if($member !== 'takeshi'){
    array_push($team,$member);
  }
}

このようにif文を用いて特定の条件に該当する要素を弾くことで対応出来た。

以上。

0
1
3

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?