Monday, 9 January 2017
php - Error When Pushing Key/Value Pair Array with array_push
Answer
Answer
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!
Answer
you could simply do as:
$holders_array = array();
foreach ($holders as $holder) {
$holders_array[] = [
"date" => $holder['date'],
"holders" => $holder['holders']
];
}
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
Iv'e read a lot of posts both in stackoverflow and other websites talking about web security. Such as salting encrypting etc. ...
-
System.out.print("Name : "); String name = in.nextLine(); System.out.print("Age : "); int age = ...
-
I would like these values to go into my database but it just won't do it. Form Code Navn: Tilføj til dine præferencer...
No comments:
Post a Comment