How to use 3-dimensional array in PHP

I do image processing in php and usually I never use an array in php before.

I need to store the value of the rgb value of the image retention in a three-dimensional array.

For instance, rgbArray[][][]

the former []is weight, the latter is []used to maintain height, and the latter is used to preserve red, greedy or blue. How can I create an array in php that can save this set of values.

Thanks in advance.

+3
source share
3 answers

I think you are looking for a two-dimensional array:

$rgbArray[$index] = array('weight'=>$weight, 'height'=>$height, 'rgb'=>$rgb);

But here is a three-dimensional array that may make sense for what you are asking.

$rgpArray[$index] = array('red'=>array('weight'=>$weight, 'height'=>$height),
                          'green'=>array('weight'=>$weight, 'height'=>$height),
                          'blue'=>array('weight'=>$weight, 'height'=>$height));
+2
source

rgbArray [1] [1] [red], , :

$rgbArray = array(1 => array(1 => array('red' => 'value')));
echo $rgbArray[1][1]['red']; // prints 'value'

, PMV :

$rgbArray = array('weight' => 1, 'height' => 1, 'rgb' => 'red' );

$rgbArray = array();
$rgbArray['weight'] = 1; // int value
$rgbArray['height'] = 1; // int value
$rgbArray['rgb'] = 'red'; // string value

, , , .

+1

$rgbArray = array('red'=>array('weight'=>$weight, 'height'=>$height),
                  'green'=>array('weight'=>$weight, 'height'=>$height),
                  'blue'=>array('weight'=>$weight, 'height'=>$height));

Then you can set the value to rgbArray, for example

$weight = $rgbArray['red']['weight']
$height = $rgbArray['red']['height']

If your array

$rgbArray = array('red'=>array($weight, $height),
                  'green'=>array($weight, $height),
                  'blue'=>array($weight, $height));

Then you can set the value to rgbArray, for example

$weight = $rgbArray['red'][0]
$height = $rgbArray['red'][1]
0
source

Source: https://habr.com/ru/post/1773274/


All Articles