Jump to content

Recommended Posts

Hello Guys,

 

I have this problem:

 

<?php
// ... code stripped

print_r($node_array);

echo "Array Count: " . $count($node_array) . "<br>";

$node = 30207;
echo "Temperature for node " . $node . " -> " . $node_array[$node]; 
?> 

 

And the Output:

Array ( [0] => Array ( [30207] => 338.54 ) [1] => Array ( [606121 ] => 338.54 ) [2] => Array ( [606122 ] => 338.54 ) [3] => Array ( [606218 ] => 338.54 ) [4] => Array ( [606219 ] => 338.54 ) [5] => Array ( [783907 ] => 338.54 ) [6] => Array ( [784282 ] => 338.54 ) [7] => Array ( [784283 ] => 338.54 ) [8] => Array ( [784284 ] => 338.54 ) [9] => Array ( [784285 ] => 338.54 ) [10] => Array ( [784395 ] => 338.54 ) [11] => Array ( [784397 ] => 338.54 ) [12] => Array ( [784398 ] => 338.54 ) [13] => Array ( [784745 ] => 338.54 ) [14] => Array ( [784746 ] => 338.54 ) [15] => Array ( [784748 ] => 338.54 ) [16] => Array ( [784932 ] => 338.54 ) [17] => Array ( [784933 ] => 338.54 ) [18] => Array ( [785370 ] => 338.54 ) [19] => Array ( [785388 ] => 338.54 ) [20] => Array ( [786035 ] => 338.54 ) [21] => Array ( [786036 ] => 338.54 ) [22] => Array ( [786037 ] => 338.54 ) [23] => Array ( [786040 ] => 338.54 ) [24] => Array ( [786042 ] => 338.54 ) [25] => Array ( [786045 ] => 338.54 ) [26] => Array ( [787064 ] => 338.54 ) [27] => Array ( [787065 ] => 338.54 ) [28] => Array ( [787067 ] => 338.54 ) [29] => Array ( [787068 ] => 338.54 ) [30] => Array ( [787069 ] => 338.54 ) -> TO BIG TO POST

 

Array Count: 11482

Temperature for node 30207 -> <EMPTY>

 

 

PHP is not printing the temperature for my specified node, what I'm doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/182899-multidimensional-array-problem/
Share on other sites

because your keys aren't the nodes they're auto incremented.

 

like this

$node_array[0]=array(array($node1=>"338.54"),array($node2=>"338.54"))  // etc.. etc..

to do it your way it would have to be

$node_array=array($node1=>"338.54";$node2=>"338.54"); 

because your keys aren't the nodes they're auto incremented.

 

like this

$node_array[0]=array(array($node1=>"338.54"),array($node2=>"338.54"))  // etc.. etc..

to do it your way it would have to be

$node_array=array($node1=>"338.54";$node2=>"338.54"); 

 

I'm using this code to add values to my array:

 

$index_array = array($thermal_node => $esatan_temp);	
array_push($node_array, $index_array);

 

try

<?php
$node_array = Array ( '0' => Array ( '30207' => 338.54 ),
				 '1' => Array ( '606121 ' => 338.54 ),
				 '2' => Array ( '606122 ' => 338.54 ),
				 '3' => Array ( '606218 ' => 338.54 ),
				 '4' => Array ( '606219 ' => 338.54 ), 
				 '5' => Array ( '783907 ' => 338.54 ), 
				 '6' => Array ( '784282 ' => 338.54 ), 
				 '7' => Array ( '784283 ' => 338.54 ), 
				 '8' => Array ( '784284 ' => 338.54 ), 
				 '9' => Array ( '784285 ' => 338.54 ), 
				 '10' => Array ( '784395 ' => 338.54 ), 
				 '11' => Array ( '784397 ' => 338.54 ), 
				 '12' => Array ( '784398 ' => 338.54 ), 
				 '13' => Array ( '784745 ' => 338.54 ), 
				 '14' => Array ( '784746 ' => 338.54 ), 
				 '15' => Array ( '784748 ' => 338.54 ), 
				 '16' => Array ( '784932 ' => 338.54 ), 
				 '17' => Array ( '784933 ' => 338.54 ), 
				 '18' => Array ( '785370 ' => 338.54 ), 
				 '19' => Array ( '785388 ' => 338.54 ), 
				 '20' => Array ( '786035 ' => 338.54 ), 
				 '21' => Array ( '786036 ' => 338.54 ), 
				 '22' => Array ( '786037 ' => 338.54 ), 
				 '23' => Array ( '786040 ' => 338.54 ), 
				 '24' => Array ( '786042 ' => 338.54 ), 
				 '25' => Array ( '786045 ' => 338.54 ), 
				 '26' => Array ( '787064 ' => 338.54 ), 
				 '27' => Array ( '787065 ' => 338.54 ), 
				 '28' => Array ( '787067 ' => 338.54 ), 
				 '29' => Array ( '787068 ' => 338.54 ), 
				 '30' => Array ( '787069 ' => 338.54 ));
$node_array1 = array();
foreach ($node_array as $a) foreach ($a as $k => $v)$node_array1[$k] = $v;
print_r($node_array1);
echo "Array Count: " . count($node_array) . "<br>";
$node = 30207;
echo "Temperature for node " . $node . " -> " . $node_array1[$node]; 
?>

try

<?php
$node_array = Array ( '0' => Array ( '30207' => 338.54 ),
				 '1' => Array ( '606121 ' => 338.54 ),
				 '2' => Array ( '606122 ' => 338.54 ),
				 '3' => Array ( '606218 ' => 338.54 ),
				 '4' => Array ( '606219 ' => 338.54 ), 
				 '5' => Array ( '783907 ' => 338.54 ), 
				 '6' => Array ( '784282 ' => 338.54 ), 
				 '7' => Array ( '784283 ' => 338.54 ), 
				 '8' => Array ( '784284 ' => 338.54 ), 
				 '9' => Array ( '784285 ' => 338.54 ), 
				 '10' => Array ( '784395 ' => 338.54 ), 
				 '11' => Array ( '784397 ' => 338.54 ), 
				 '12' => Array ( '784398 ' => 338.54 ), 
				 '13' => Array ( '784745 ' => 338.54 ), 
				 '14' => Array ( '784746 ' => 338.54 ), 
				 '15' => Array ( '784748 ' => 338.54 ), 
				 '16' => Array ( '784932 ' => 338.54 ), 
				 '17' => Array ( '784933 ' => 338.54 ), 
				 '18' => Array ( '785370 ' => 338.54 ), 
				 '19' => Array ( '785388 ' => 338.54 ), 
				 '20' => Array ( '786035 ' => 338.54 ), 
				 '21' => Array ( '786036 ' => 338.54 ), 
				 '22' => Array ( '786037 ' => 338.54 ), 
				 '23' => Array ( '786040 ' => 338.54 ), 
				 '24' => Array ( '786042 ' => 338.54 ), 
				 '25' => Array ( '786045 ' => 338.54 ), 
				 '26' => Array ( '787064 ' => 338.54 ), 
				 '27' => Array ( '787065 ' => 338.54 ), 
				 '28' => Array ( '787067 ' => 338.54 ), 
				 '29' => Array ( '787068 ' => 338.54 ), 
				 '30' => Array ( '787069 ' => 338.54 ));
$node_array1 = array();
foreach ($node_array as $a) foreach ($a as $k => $v)$node_array1[$k] = $v;
print_r($node_array1);
echo "Array Count: " . count($node_array) . "<br>";
$node = 30207;
echo "Temperature for node " . $node . " -> " . $node_array1[$node]; 
?>

 

Thats for the explanation!

 

How can I dynamically add values to the array?

 

I was trying...

 

while($i < 10) {
echo $i;
$node_array = Array ( $i => Array ( $node => $temp ));
$i++;
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.