Home > database >  How to push (Arrow Function) into array?
How to push (Arrow Function) into array?

Time:11-15

I am trying to insert code (double Arrow) into an array. But no matter how I try, I can't get it to work. My actual attempt is to push the new code to the variable but I'm getting this error:

"syntax error, unexpected '=>' (T_DOUBLE_ARROW)"

What is the right way to add code to that array?

    $shortcode[] = 'attendee_name' => $tickets[0]['shortcode_data']['attendee_name'];
    
    $shortcode = array(
        'product_name'  => $tickets[0]['shortcode_data']['product_name'],
        'start_time'    => $tickets[0]['shortcode_data']['start_time'],
        'end_time'      => $tickets[0]['shortcode_data']['end_time'],
    );

Thanks!

CodePudding user response:

you probably want to just assign to a key:

$shortcode = array(...);

$shortcode['attendee_name'] =  $tickets[0]['shortcode_data']['attendee_name'];

CodePudding user response:

Easiest way would be to just assign

$shortcode = $tickets[0]['shortcode_data'];

print_r($shortcode) would then output:

Array
(
    [attendee_name] => 12
    [product_name] => 12
    [start_time] => 12
    [end_time] => 12
)
  •  Tags:  
  • php
  • Related