Welcome Guest, Not a member yet? Register   Sign In
Unable to add to array
(This post was last modified: 06-15-2022, 03:53 PM by Sincere.)

I've done this many times before: adding an array to an yet already existing array, but for some reason this isn't working now, and I'm out of clues:
PHP Code:
$influx_server_data = [];
$stats = [
                    'health'        =>  $health,
                    'total_live'    =>  $server->live_total,
//etc etc/
                    'mem_used'      =>  $server->system_stats->memory->used,
                    'mem_total'      =>  $server->system_stats->memory->total,

                //Influx Magic

                // Server influx data
                foreach($stats as $measurement => $value){
                    $influx_server_point = [$measurement//name of measurement
                        $value//measurement value
                        ['host' => $live_server->hostname'region' => $live_server->region], // optional tags
                    $influx_server_data $influx_server_data + [$influx_server_point];

But for some reason $influx_server_data will only have the array from the first run (health in this case). The first print_r confirms that the foreach works fine and shows the desired array for each run.
I'd be grateful for any insights!

@kenjis helped solve this:
I had to do the following:
PHP Code:
$influx_server_data[] = [$influx_server_point]; 

(This post was last modified: 06-16-2022, 12:35 AM by InsiteFX.)

PHP Code:
$result array_merge($array1$array2); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB