php - How to insert an array to an array -
i add array within existing array. tryin use array_push works long dont try assign key array (if try add key syntax error... :-()
this initial array:
$resultarray = array( "transactiondate" => "$transactiondate", "tx"=>array( "0"=>array( "txindex" => "$txindex", "value" => "$value", "paymentconfirmedcount" => "$paymentconfirmedcount" ), "1"=>array( "txindex" => "$txindex", "value" => "$value", "paymentconfirmedcount" => "$paymentconfirmedcount" ) ) );
i add:
$arraytoadd = array( "0"=>array( "txindex" => "$txindex", "value" => "$value", "paymentconfirmedcount" => "$paymentconfirmedcount" ) );
if try:
array_push($resultarray->tx, $arraytoadd);
but not work , results in warning of "array_push() [function.array-push]: first argument should array"
if try :
array_push($resultarray, $arraytoadd);
it adds array not $resultarray->tx
any suggestions welcomed!
you have access element in array $resultarray["tx"]
, not $resultarray->tx
. second 1 access members in php class. an
array_push($resultarray["tx"], $arraytoadd);
should work.
Comments
Post a Comment