tags:

views:

91

answers:

5

I found this code below in a script, I am trying to figure out if it is actually supposed to do more then I am seeing, As far as I can tell it results in an array of:

$maxSize[0] with $new_width
$maxSize[1] with $source_width

$maxSize = array($new_width ? $new_width : $source_width, $new_height ? $new_height : $source_height);
A: 

It creates an array with two elements. If $new_width is set and larger than zero, the first element will be $new_width. If not, it will be $source_width. The same applies to the latter, just with height. Read ternary comparison operator for more information.

Electro
+3  A: 

It's using inline if statments. If $new_width is set, it will use that value. Otherwise, it defaults to $source_width. The same is true for $new_height. And Yes, you do get a numerically keyed array with two values.

I see now thanks
jasondavis
A: 

$maxSize[0] will be equal to $new_width if $new_width exists, else $source_width
$maxSize[1] will be equal to $new_height if $new_height exists, else $source_ height

See this: http://en.wikipedia.org/wiki/Ternary%5Foperation

Srirangan
+2  A: 

It results in an array with 2 indexes. But it does 2 ternary comparison checks to see what those indexes should equal.

For the first one if $new_width has a value, it'll use that other wise it'll use $source_width.

For the second one if $new_height has a value it'll use that other wise it'll use $source_height.

This can be expanded as:

$maxSize = array();
if ($new_width)
  $maxSize[] = $new_width;
else
  $maxSize[] = $source_width;

if ($new_height)
  $maxSize[] = $new_height;
else
  $maxSize[] = $source_height;
Steven Surowiec
A: 

It creates a array with two elements. The first element is set the width.if there is a new width set, then it defaults to the source width. It same with the second element, setting the height.

Daisy Moon