将键值对添加到现有数组或合并它们

I have to arrays:

$tickets = $db->loadObjectList();
$tickets_info = $details['ticket_info'];

$tickets:

array (size=2)

0 => 
object(stdClass)[2924]
  public 'price' => string '100.000' 
  public 'name' => string 'Standard ticket'
1 => 
object(stdClass)[2972]
  public 'price' => string '150.000' 
  public 'name' => string 'Luxus ticket'

$tickets_info:

array (size=2)
0 => string '98'
1 => string '50' 

I'm trying to add the 98 and 50 as 'available_tickets' to $tickets array like this:

0 =>
object(stdClass)[2924]
  public 'price' => string '100.000'
  public 'name' => string 'Standard ticket'
  public 'available_tickets' => string '98'
1 =>
object(stdClass)[2972]
  public 'price' => string '150.000'
  public 'name' => string 'Luxus ticket'
  public 'available_tickets' => string '50'

I have tried array_merge() and loop through, but nothing seems to work for me.

查看全部
douyong1908
douyong1908
2016/05/20 08:34
  • php
  • arrays
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复