How to: array_push into multiple array with a strict hierarchy?

Friday, July 11, 2014

I'm trying to build an archive-class for my firebird database. And I have the following problem a couple of times already:


I want to construct an array-structure like that:



/**
* @var [] stores the success log of all db operations
*
* $_log = Array(
* (string) [DATA_SOURCE] => Array(
* (int) [0] => Array(
* (string) [id] => (int) 32,
* (string) [action] => (string) "update/insert/delete",
* (string) [state] => (int) 1,
* (string) [message] => (string) "success/error",
* )
* )
* )
*/
private $_log = array();


MY 1. TRY:



// push result to log array
array_push(
$this->_log,
array(
"archive" => array(
"id" => $row["ID"],
"action" => "update",
"state" => $success,
),
)
);


RESULTS IN:



Array(
[0] => Array(
[archive] => Array(
[id] => 32
[action] => update
[state] => 1
)

)
)


MY 2nd TRY



array_push(
$this->_log["archive"],
array(
"id" => $row["ID"],
"action" => "update",
"state" => $success,
)
);


RESULTS IN



<br />
<b>Warning</b>: array_push() expects parameter 1 to be array, null given in <b>/Users/rsteinmann/web/intranet/pages/firebird/ArchiveTables.php</b> on line <b>238</b><br />


I'm a bit helpless with this task. I also tried to find anything on google or stackoverflow but there was nothing really useful.


I would be so glad if someone could help me with that!


Thank you, Raphael







http://ift.tt/1oqWaci