タグ

2014年2月14日のブックマーク (4件)

  • PHPで連想配列の配列のソート

    連想配列の配列をソートしたい $users = array( array( 'id' => 1, 'username' => 'katty0324', 'following' => 191, 'follower' => 612 ), array( 'id' => 2, 'username' => 'yutomukoyama', 'following' => 947, 'follower' => 1840 ), array( 'id' => 3, 'username' => 't_ishiyama', 'following' => 560, 'follower' => 746 ), ); こういうユーザー一覧みたいな配列をソートしたくなることがありますよね。データベースから取り出した直後の状態っていうのはだいたいこんな感じですし。たとえばユーザーID順であったり、フォロワー数順であったり。

    PHPで連想配列の配列のソート
    a20130517
    a20130517 2014/02/14
    “usortは独自に定義した関数を元にソートを実行できます。 usort($users, function($a, $b) { return $a['following'] < $b['following']; });”
  • PHP: create_function - Manual

    Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Su

    PHP: create_function - Manual
  • PHP: usort - Manual

    Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Su

    PHP: usort - Manual
  • MySQLのgroup_concatで複数レコードを1行にまとめる - 文系プログラマによるTIPSブログ

    実は非常に有用で、この機能が実は欲しかった!と言う方が続出する機能なのですよね〜 全然知らなかったのですが、mysqlでは複数レコードを1行にまとめる事ができます。 複数行をカンマ区切りにしたり、結構有効に使えそうです。 テーブル・データの準備 テーブル データ 実際に実行してみる 普通にselectしてみる group_concatしてみる group_concat + distinct group_concat + group by テーブル・データの準備 早速サンプルコードを。 テーブル mysql> create table gc1(id int auto_increment, uid int, name varchar(30), primary key(id))engine=innodb charset=utf8mb4; Query OK, 0 rows affected (0.

    MySQLのgroup_concatで複数レコードを1行にまとめる - 文系プログラマによるTIPSブログ