-1

I'm trying to push a key/value pair to an array like so:

$holders_array = array();

foreach ($holders as $holder) {
    array_push($holders_array, "date" => $holder['date'], "holders" => $holder['holders']);
}

But I am getting the error:

Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in

I see that you cannot push key-value pairs with array_push according to this link, however, I can't figure out how to get it right.

What do I need to do to push the key value pair to the array? Thanks!

0

2 Answers 2

1

you could simply do as:

$holders_array = array();

foreach ($holders as $holder) {
    $holders_array[] = [
        "date" => $holder['date'],
        "holders" => $holder['holders']
    ];
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can write your logic like

foreach ($holders as $holder) {
    $date_array['date'] = $holder['date'];
    $holder_array['holders'] = $holder['holders'];
    array_merge($holders_array, $date_array,$holder_array);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.