1
0

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エラー】

Posted at

PHP Notice

Only variables should be passed by reference in エラーの対処
なんでNotice出るのか理解できたのでメモ

  /*  $rows 配列が入ってる
   *  $key 配列の最後のキーをint型で入れたい
   *  $ary_rows 参照渡し用キーを入れる配列
   */

  
  $key = (int)end(array_keys($rows)); // 1行で済むけど参照渡しになってない

  // ↑を分解してarray_keysの配列を一旦変数に入れてやるとNoticeエラーが出ない
  $ary_rows = array_keys($rows); // 配列のキーを入れてる
  $key = (int)end($ary_rows); // 配列のキーの最後のキーを入れてる
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?