add array element to row returned from sql query
Posted
by bert
on Stack Overflow
See other posts from Stack Overflow
or by bert
Published on 2010-04-03T00:04:58Z
Indexed on
2010/04/03
0:13 UTC
Read the original article
Hit count: 204
I want to add an additional value into an array before passing it to json_encode function, but I can't get the syntax right.
$result = db_query($query);
// $row is a database query result resource
while ($row = db_fetch_object($result)) {
$stack[] = $row;
// I am trying to 'inject' array element here
$stack[]['x'] = "test";
}
echo json_encode($stack);
© Stack Overflow or respective owner