-1

配列に格納されているオブジェクトを使用する方法を明確にしたいだけですか? Laravel では、クエリをトリガーします。

$accounts = Account::where('customer_no', '=', $customer->customer_no)->get();

これは、配列内の 2 つのオブジェクトを返します。ここでは、ダイとダンプです。

array(2) {
  [0]=>
   object(Account)#40 (5) {
 ["attributes"]=>
 array(11) {
  ["acc_no"]=>
  int(5)
  ["acc_type"]=>
  string(7) "CURRENT"
  ["start_date"]=>
  string(19) "2012-09-05 00:00:00"
  ["status"]=>
  int(1)
  ["balance"]=>
  string(5) "57.67"
  ["end_date"]=>
  NULL
  ["interest_rate"]=>
  string(4) "0.60"
  ["pin"]=>
  string(4) "1112"
  ["attempts"]=>
  int(2)
  ["bank_code"]=>
  int(1)
  ["customer_no"]=>
  int(10000003)
}
[1]=>
  object(Account)#43 (5) {
  ["attributes"]=>
  array(11) {
  ["acc_no"]=>
  int(6)
  ["acc_type"]=>
  string(7) "SAVINGS"
  ["start_date"]=>
  string(19) "2007-01-01 00:00:00"
  ["status"]=>
  int(1)
  ["balance"]=>
  string(7) "1002.01"
  ["end_date"]=>
  NULL
  ["interest_rate"]=>
  string(4) "0.80"
  ["pin"]=>
  string(4) "3427"
  ["attempts"]=>
  int(2)
  ["bank_code"]=>
  int(1)
  ["customer_no"]=>
  int(10000003)
}

したがって、これらのオブジェクトに個別にアクセスして、foreach を実行して個別にアクセスするのではなく、それらを利用できるようにしたいと考えています。

これらのオブジェクトを PHP で個別に保存するにはどうすればよいですか?

4

1 に答える 1

1

配列インデックスからオブジェクトを取得できます。

$account_one = $accounts[0];
$account_two = $accounts[1];

を使いたくない理由はありforeachますか?通常のforループを使用$accounts[i]して、特定のアカウントを参照することもできます。

于 2013-03-13T18:12:36.060 に答える