开发者

How to get this array value? (php)

Sorry guys i'm actually trying to debug this code justpaste.it/fh8 because i cant get it to working. So i suspect it have something to do with the array

I have this array $compare_colours['red']. When i var_dump it will give this value:

int(255) int(252) int(255) int(255) int(255) int(164) int(116) int(194) int(255) int(100) int(0) int(0) int(1)

Now how i can manually get the first or second value? So the the first value will be 255 and the 2nd value will be 252.

I try with $compare_colours['red'][0],$compare_colours'red' but only get null value.

Thanks.

I get the $compare_colours array from this code

$compare_colors = imagecolorsforindex($compare_pic, $compare_rgb);

Here is the print_r from $compare_colours

Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 127 ) 
Array ( [red] => 252 [green] => 252 [blue] => 252 [alpha] => 126 ) 
Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 127 ) 
Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 127 ) 
Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 127 ) 
Array ( [red] => 164 [green] => 218 [blue] => 148 [alpha] => 44 ) 
Array ( [red] => 116 [green] => 202 [blue] => 115 [alpha] => 21 ) 
Array ( [red] => 194 [green] => 230 [blue] => 182 [alpha] => 64 ) 
Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 127 ) 
Array ( [red] => 100 [green] => 100 [blue] => 100 [alpha] => 50 ) 
Array ( [red] => 0 [green] => 0 [blue] => 0 [alpha] => 0 ) 
Array ( [red] => 0 [green] => 0 [blue] => 0 [alpha] => 0 )

When i use var_dump($compare_colors);

array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255)开发者_StackOverflow中文版 ["alpha"]=> int(127) }
array(4) { ["red"]=> int(252) ["green"]=> int(252) ["blue"]=> int(252) ["alpha"]=> int(126) } 
array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) } 
array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) } 
array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) } 
array(4) { ["red"]=> int(164) ["green"]=> int(218) ["blue"]=> int(148) ["alpha"]=> int(44) } 
array(4) { ["red"]=> int(116) ["green"]=> int(202) ["blue"]=> int(115) ["alpha"]=> int(21) } 
array(4) { ["red"]=> int(194) ["green"]=> int(230) ["blue"]=> int(182) ["alpha"]=> int(64) } 
array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) } 
array(4) { ["red"]=> int(100) ["green"]=> int(100) ["blue"]=> int(100) ["alpha"]=> int(50) } 
array(4) { ["red"]=> int(0) ["green"]=> int(0) ["blue"]=> int(0) ["alpha"]=> int(0) } 
array(4) { ["red"]=> int(0) ["green"]=> int(0) ["blue"]=> int(0) ["alpha"]=> int(0) } 


If $compare_colours is array of colours then you shoud do it the other way around:

 echo $compare_colours[0]['red'].' '.$compare_colours[1]['red'];


try if you get any output by the following code.

echo $compare_colours[0]['red']; OR echo $compare_colors['red'];


You could to a foreach loop:

$index = 0;
foreach ($compare_colours['red'] as $k => $v) {
  if ($index == 0) {
    $first_value = $v;
  }
  if ($index == 1) {
    $second_value = $v;
    break;
  }
  $index = $index + 1;
}

Maybe there is a smarter thing but this is quite fast because you only loop 2 times.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜